public void InstallTheService()
 {
     try
     {
         IDictionary state = new Hashtable();
         using (AssemblyInstaller installer = new AssemblyInstaller(InstallersAssembly, Args))
         {
             installer.UseNewContext = true;
             try
             {
                 installer.Install(state);
                 installer.Commit(state);
                 InternalTrace("Installed the service");
             }
             catch (Exception installException)
             {
                 try
                 {
                     installer.Rollback(state);
                     InternalTrace("Rolledback the service installation because:" + installException.ToString());
                 }
                 catch { }
                 throw;
             }
         }
     }
     catch (Exception exception)
     {
         InternalTrace("Failed to install the service " + exception.ToString());
     }
 }
Exemple #2
0
 /// <summary>
 /// 安装windows服务
 /// </summary>
 private void InstallService(IDictionary stateSaver, string filepath, string serviceName)
 {
     try
     {
         ServiceController service = new ServiceController(serviceName);
         if (!ServiceIsExisted(serviceName))
         {
             AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
             myAssemblyInstaller.UseNewContext = true;
             myAssemblyInstaller.Path = filepath;
             myAssemblyInstaller.Install(stateSaver);
             myAssemblyInstaller.Commit(stateSaver);
             myAssemblyInstaller.Dispose();
             service.Start();
         }
         else
         {
             if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
                 service.Start();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("InstallServiceError\r\n" + ex.Message);
     }
 }
        public static void Install(string[] args)
        {
            try
            {
                using (var installer = new AssemblyInstaller(typeof(InstallationManager).Assembly, args))
                {
                    IDictionary state = new Hashtable();

                    // Install the service
                    installer.UseNewContext = true;
                    try
                    {
                        installer.Install(state);
                        installer.Commit(state);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);

                        try
                        {
                            installer.Rollback(state);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.Message);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed to install service. Error: " + exception.Message);
            }
        }
 static void Install(bool undo, string[] args)
 {
     try
     {
         Console.WriteLine(undo ? "Uninstalling" : "Installing");
         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WinSvc).Assembly, args))
         {
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if (undo) inst.Uninstall(state);
                 else
                 {
                     inst.Install(state);
                     inst.Commit(state);
                 }
             }
             catch
             {
                 try { inst.Rollback(state); }
                 catch { }
                 throw;
             }
         }
         Console.WriteLine("Done");
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex.Message);
     }
 }
Exemple #5
0
        private void Install(AssemblyInstaller installer, IDictionary state, bool undo)
        {

            try
            {
                if (undo)
                {
                    _log.Write(LogLevel.Info, "Uninstalling {0}...", StringConstants.ServiceName);
                    installer.Uninstall(state);
                    _log.Write(LogLevel.Info, "{0} has been successfully removed from the system.", StringConstants.ServiceName);
                }
                else
                {
                    _log.Write(LogLevel.Info, "Installing {0}...", StringConstants.ServiceName);
                    installer.Install(state);

                    _log.Write(LogLevel.Info, "Commiting changes...");
                    installer.Commit(state);

                    _log.Write(LogLevel.Info, "Install succeeded.");
                }
            }
            catch (Exception ex)
            {
                _log.Write(LogLevel.Error, "An error occured during {1}. {0}", ex, undo?"uninstall" : "install");
                _log.Write(LogLevel.Info, "Trying to roll back...");
                TryRollback(installer, state);
            }
        }
 /// <summary>
 /// 安装服务:
 /// </summary>
 /// <param name="filepath"></param>
 public void InstallService(string filepath)
 {
     try
     {
         string serviceName = GetServiceName(filepath);
         ServiceController service = new ServiceController(serviceName);
         if (!ServiceIsExisted(serviceName))
         {
             //Install Service
             AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller() { UseNewContext = true, Path = filepath };
             myAssemblyInstaller.Install(new Hashtable());
             myAssemblyInstaller.Commit(new Hashtable());
             myAssemblyInstaller.Dispose();
             //--Start Service
             service.Start();
         }
         else
         {
             if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
             {
                 service.Start();
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("installServiceError/n" + ex.Message);
     }
 }
        public void InstallService(string user, string pass) {
            using (AssemblyInstaller installer = new AssemblyInstaller(Path.Combine(Utils.GetApplicationPath(), Utils.GetExecutableName()), null)) {
                installer.UseNewContext = true;
                Hashtable savedState = new Hashtable();

                UserPassCombination c = new UserPassCombination();
                c.User = user;
                c.Pass = pass;
                _userPassCombination = c;

                installer.BeforeInstall += new InstallEventHandler(installer_BeforeInstall);

                //Rollback has to be called by user code. According msdn-doc for AssemblyInstaller.Install() is probably wrong.
                try {
                    installer.Install(savedState);
                    installer.Commit(savedState);
                }
                catch (Exception ex) {
                    installer.Rollback(savedState);
                    throw new InstallException(String.Format("Install failed: {0}", ex.Message), ex);
                }

                installer.BeforeInstall -= installer_BeforeInstall;
            }
        }
Exemple #8
0
        public static bool InstallWindowsService()
        {
            IDictionary mySavedState = new Hashtable();           

            try
            {
                // Set the commandline argument array for 'logfile'.
                string[] commandLineOptions = new string[1] { string.Format("/LogFile={0}", _logFile) };

                // Create an object of the 'AssemblyInstaller' class.
                AssemblyInstaller myAssemblyInstaller = new
                AssemblyInstaller(_installAssembly, commandLineOptions);
                

                myAssemblyInstaller.UseNewContext = true;

                // Install the 'MyAssembly' assembly.
                myAssemblyInstaller.Install(mySavedState);

                // Commit the 'MyAssembly' assembly.
                myAssemblyInstaller.Commit(mySavedState);
            }
            catch (Exception e)
            { return false; }

            StartService();
            return true;
        }
 /// <summary>
 /// 安装Windows服务
 /// </summary>
 /// <param name="stateSaver">状态集合</param>
 /// <param name="filepath">程序文件路径</param>
 public static void InstallService(IDictionary stateSaver, String filepath)
 {
     AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
     AssemblyInstaller1.UseNewContext = true;
     AssemblyInstaller1.Path = filepath;
     AssemblyInstaller1.Install(stateSaver);
     AssemblyInstaller1.Commit(stateSaver);
     AssemblyInstaller1.Dispose();
 }
        /// <summary>
        /// Install the service that is contained in specified assembly.
        /// </summary>
        /// <param name="pathToAssembly">Path to service assembly.</param>
        /// <param name="commandLineArguments">Parameters, that are passed to assembly.</param>
        public static void InstallAssembly(string pathToAssembly, string[] commandLineArguments)
        {
            List<string> argList = new List<string>(commandLineArguments);

            argList.Add(string.Format("/LogFile={0}_install.log",
                                        Path.GetFileNameWithoutExtension(pathToAssembly)));
            using (AssemblyInstaller installer = new AssemblyInstaller(pathToAssembly, argList.ToArray())) {
                var state = new Hashtable();
                installer.Install(state);
                installer.Commit(state);
            }
        }
        /// <summary>
        /// Acrescenta um serviço do windows no registro
        /// </summary>
        public static void InstallService(String fileName)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
            String serviceName = Path.GetFileNameWithoutExtension(fileName);
            String[] arguments = new string[] { "/LogFile=" + serviceName + "_Install.log" };
            IDictionary state = new Hashtable();

            AssemblyInstaller installer = new AssemblyInstaller(fileName, arguments);
            installer.UseNewContext = true;
            installer.Install(state);
            installer.Commit(state);
        }
Exemple #12
0
        static void Install(bool undo, string[] args)
        {
            try
            {
                Console.WriteLine(undo ? "uninstalling" : "installing");
                using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);
                            try
                            {
                                ServiceController service = new ServiceController("DpFamService");
                                TimeSpan timeout = TimeSpan.FromMilliseconds(1000);

                                service.Start();
                                service.WaitForStatus(ServiceControllerStatus.Running, timeout);

                            }
                            catch
                            {
                                Console.WriteLine("Could not start the server\n");
                            }

                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
Exemple #13
0
        public static void InstallService()
        {
            string exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string strDir = System.IO.Path.GetDirectoryName(exePath);
            string filepath = strDir + "\\MPlayerWWService.exe";

            IDictionary mSavedState = new Hashtable();
            AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
            myAssemblyInstaller.UseNewContext = true;
            myAssemblyInstaller.Path = filepath;
            myAssemblyInstaller.Install(mSavedState);
            myAssemblyInstaller.Commit(mSavedState);
            myAssemblyInstaller.Dispose();
        }
        public static bool Install()
        {
            Tracker.StartServer();

            bool result = true;

            InstallContext context = null;
            try
            {
                using (var inst = new AssemblyInstaller(typeof (ServerLifecycleManager).Assembly, null))
                {
                    context = inst.Context; 
                    LogMessage("Installing service " + AppSettings.ServiceName, inst.Context);
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;

                    try
                    {
                        inst.Install(state);
                        inst.Commit(state);
                        Tracker.TrackEvent(TrackerEventGroup.Installations, TrackerEventName.Installed);
                    }
                    catch (Exception err)
                    {
                        Tracker.TrackException("WindowsServiceManager", "Install", err);
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch (Exception innerErr)
                        {
                            throw new AggregateException(new List<Exception> {err, innerErr});
                        }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                WriteExceptions(ex, context);
            }
            finally
            {
                Tracker.Stop();
            }

            return result;
        }
Exemple #15
0
 /// <summary>
 /// 安装Windows服务
 /// </summary>
 /// <param name="stateSaver">集合,当传递给 Install 方法时,stateSaver 参数指定的 IDictionary 应为空。</param>
 /// <param name="filepath">程序文件路径</param>
 public static void InstallmyService(IDictionary stateSaver, string filepath)
 {
     try
     {
         AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
         AssemblyInstaller1.UseNewContext = true;
         AssemblyInstaller1.Path = filepath;
         stateSaver.Clear();
         AssemblyInstaller1.Install(stateSaver);
         AssemblyInstaller1.Commit(stateSaver);
         AssemblyInstaller1.Dispose();
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message.ToString());
     }
 }
 // References http://stackoverflow.com/questions/1195478/how-to-make-a-net-windows-service-start-right-after-the-installation/1195621#1195621
 public static void Install()
 {
     using (AssemblyInstaller installer =
             new AssemblyInstaller(typeof(OpenVpnService).Assembly, null))
     {
         installer.UseNewContext = true;
         var state = new System.Collections.Hashtable();
         try
         {
             installer.Install(state);
             installer.Commit(state);
         } catch
         {
             installer.Rollback(state);
             throw;
         }
     }
 }
Exemple #17
0
        static void Install(bool undo, string[] args)
        {
            try
            {
                Logger.Log(undo ? "Uninstalling ..." : "Installing ... ");
                using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    var state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);

                            StartService();
                        }
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            Logger.Log(ex);
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                    inst.Dispose();
                }
                Logger.Log("... finished");
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Exemple #18
0
		public void OnAction(Hashtable parameters)
		{
			ArrayList temp = new ArrayList();
			temp.Add("/LogToConsole=false");
			StringBuilder tempString = new StringBuilder();
			foreach(DictionaryEntry entry in parameters)
			{
				if(tempString.Length > 0)
					tempString.Append(" ");
				tempString.Append(entry.Key);
				tempString.Append("=");
				tempString.Append(entry.Value);
			}
			temp.Add("commandline="+tempString.ToString());
			
			string[] commandLine = (string[]) temp.ToArray(typeof(string));

			System.Configuration.Install.AssemblyInstaller asmInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), commandLine);
			Hashtable rollback = new Hashtable();

			if (GameServerService.GetDOLService() != null)
			{
				Console.WriteLine("DOL service is already installed!");
				return;
			}

			Console.WriteLine("Installing DOL as system service...");
			try
			{
				asmInstaller.Install(rollback);
				asmInstaller.Commit(rollback);
			}
			catch (Exception e)
			{
				asmInstaller.Rollback(rollback);
				Console.WriteLine("Error installing as system service");
				Console.WriteLine(e.Message);
				return;
			}
			Console.WriteLine("Finished!");
		}
        public static bool Install(bool undo, string[] args)
        {
            try
            {
                Console.WriteLine(undo ? "Uninstalling..." : "Installing...");
                using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WakeService).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);
                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }

            return false;
        }
Exemple #20
0
 /// <summary>
 /// 安装windows服务
 /// </summary>
 /// <param name="serviceName">服务名称</param>
 /// <param name="savedState">它用于保存执行提交、回滚或卸载操作所需的信息。</param>
 /// <param name="filepath">获取或设置要安装的程序集的路径。</param>
 public static void InstallService(String serviceName, IDictionary savedState, string filepath)
 {
     ServiceController service = new ServiceController(serviceName);
     if (!ServiceIsExisted(serviceName))
     {
         AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
         myAssemblyInstaller.UseNewContext = true;
         myAssemblyInstaller.Path = filepath;
         myAssemblyInstaller.Install(savedState);
         myAssemblyInstaller.Commit(savedState);
         myAssemblyInstaller.Dispose();
         service.Start();
     }
     else
     {
         if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
         {
             service.Start();
         }
     }
 }
 public static bool Install(bool undo, string[] args)
 {
     try
     {
         using(var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
         {
             inst.AfterInstall += OnAfterInstall;
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if(undo)
                     inst.Uninstall(state);
                 else
                 {
                     inst.Install(state);
                     inst.Commit(state);
                 }
             }
             catch
             {
                 try
                 {
                     inst.Rollback(state);
                 }
                 catch
                 {
                     return false;
                 }
                 throw;
             }
         }
     }
     catch(Exception ex)
     {
         Console.WriteLine(ex);
         return false;
     }
     return true;
 }
Exemple #22
0
 /// <summary>
 /// Actually installs/uninstalls this service.
 /// </summary>
 /// <param name="undo"></param>
 /// <param name="args"></param>
 private static void Install(bool undo, string[] args)
 {
     try
     {
         using (AssemblyInstaller installer = new AssemblyInstaller(
             Assembly.GetEntryAssembly(), args))
         {
             IDictionary savedState = new Hashtable();
             installer.UseNewContext = true;
             try
             {
                 if (undo)
                 {
                     installer.Uninstall(savedState);
                 }
                 else
                 {
                     installer.Install(savedState);
                     installer.Commit(savedState);
                 }
             }
             catch
             {
                 try
                 {
                     installer.Rollback(savedState);
                 }
                 catch
                 {
                 }
                 throw;
             }
         }
     }
     catch (Exception exception)
     {
         Console.Error.WriteLine(exception.Message);
     }
 }
Exemple #23
0
 static void Main(string[] args)
 {
     var notRun = true;
     if (args.Length > 0)
     {
         if (args[0] == "-i" || args[0] == "-I")
         {
             notRun = false;
             var stateServer = new Hashtable();
             var assemblyInstaller = new AssemblyInstaller(typeof(Program).Assembly, null);
             assemblyInstaller.Install(stateServer);
         }
         else if (args[0] == "-u" || args[0] == "-U")
         {
             notRun = false;
             var assemblyInstaller = new AssemblyInstaller(typeof(Program).Assembly, null);
             var stateServer = new Hashtable();
             assemblyInstaller.Uninstall(stateServer);
         }
     }
     if (notRun)
     {
         if (System.Diagnostics.Debugger.IsAttached == true)
         {
             const string userName = "******";
             const string password = "******";
             const string hostName = "10.26.10.150";
             var debugForm = new DebugForm(userName, password, hostName);
             debugForm.ShowDialog();
         }
         else
         {
             string userName = ConfigurationManager.AppSettings["UserName"];
             string password = ConfigurationManager.AppSettings["PassWord"];
             string hostName = ConfigurationManager.AppSettings["HostName"];
             ServiceBase.Run(new SAFTeamCityService(userName, password, hostName));
         }
     }
 }
        /// <summary>
        /// Installs the assembly specified by <see cref="P:assemblyPath" />
        /// </summary>
        /// <param name="assemblyPath">Full path to the assembly to install</param>
        public static void Install(String assemblyPath)
        {
            try
            {
                Console.WriteLine("Installing: {0}", assemblyPath);

                AssemblyInstaller installer = new AssemblyInstaller(assemblyPath, new String[] { })
                {
                    UseNewContext = true
                };

                installer.Install(null);
                installer.Commit(null);
            }
            catch (FileNotFoundException exception)
            {
                Console.WriteLine("[!] Installer state file not found, installing service without storing the state" + exception.Message);
            }
            catch (Exception exception2)
            {
                Console.WriteLine("[!] Unable to install service: " + exception2.Message);
            }
        }
Exemple #25
0
 private static void InstallService(bool undo, string[] args)
 {
     using (AssemblyInstaller inst = new AssemblyInstaller(Assembly.GetExecutingAssembly(), args)) {
         var state = new Hashtable();
         inst.UseNewContext = true;
         try {
             if (undo) {
                 inst.Uninstall(state);
             }
             else {
                 inst.Install(state);
                 inst.Commit(state);
             }
         }
         catch {
             try {
                 inst.Rollback(state);
             }
             catch { }
             throw;
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="exeFilename">Installer class (not the service class!)</param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static bool InstallService(string exeFilename, out Exception exception)
        {
            exception = null;
            string[] commandLineOptions = new string[1] {
                "/LogFile=install.log"
            };

            System.Configuration.Install.AssemblyInstaller installer =
                new System.Configuration.Install.AssemblyInstaller(exeFilename, commandLineOptions);

            try
            {
                installer.UseNewContext = true;
                installer.Install(null);
                installer.Commit(null);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(false);
            }
            return(true);
        }
 public static void Install(bool undo, string openvpn)
 {
     try
     {
         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(OpenVPNServiceRunner).Assembly, new String[0]))
         {
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if (undo)
                 {
                     inst.Uninstall(state);
                 }
                 else
                 {
                     inst.Install(state);
                     inst.Commit(state);
                     SetParameters(openvpn);
                 }
             }
             catch
             {
                 try
                 {
                     inst.Rollback(state);
                 }
                 catch { }
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex.Message);
     }
 }
Exemple #28
0
 /// <summary>
 /// Installs the service
 /// </summary>
 void Install()
 {
     Console.Write(InfoString);
     try {
         using (var i = new AssemblyInstaller(ProgramType.Assembly, null) { UseNewContext = true }) {
             var s = new Hashtable();
             try {
                 i.Install(s);
                 i.Commit(s);
             } catch {
                 try {
                     i.Rollback(s);
                 } catch { }
                 throw;
             }
         }
         Console.WriteLine(Messages.Done);
     } catch (Exception x) {
         Console.Error.WriteLine(x.Message);
         ReturnValue = 1;
     }
 }
 static void Install(bool undo, string[] args)
 {
     using (AssemblyInstaller asminstall = new AssemblyInstaller(typeof(XenService).Assembly, args))
     {
         System.Collections.IDictionary state = new System.Collections.Hashtable();
         asminstall.UseNewContext = true;
         try
         {
             if (undo)
             {
                 asminstall.Uninstall(state);
             }
             else
             {
                 asminstall.Install(state);
                 asminstall.Commit(state);
             }
         }
         catch
         {
             try
             {
                 asminstall.Rollback(state);
             }
             catch { }
         }
     }
 }
Exemple #30
0
        /// <summary>
        /// Handle installation and uninstallation.
        /// </summary>
        /// <param name="uninstall">Whether we're uninstalling.  False if installing, true if uninstalling</param>
        /// <param name="args">Any service installation arguments.</param>
        public void Install(bool uninstall, string[] args)
        {
            try
            {
                using (AssemblyInstaller installer = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    installer.UseNewContext = true;
                    try
                    {
                        // Attempt to install or uninstall.
                        if (uninstall)
                            installer.Uninstall(state);
                        else
                        {
                            installer.Install(state);
                            installer.Commit(state);
                        }
                    }
                    catch
                    {
                        // If an error is encountered, attempt to roll back.
                        try
                        {
                            installer.Rollback(state);
                        }
                        catch { }

                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
Exemple #31
-2
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            if (args.Length > 0) {
                switch (args[0]) {
                    case "-c":
                        Log = Console.WriteLine;
                        var svc = new Service();
                        svc.TestRun(args.Skip(1).ToArray());
                        Console.WriteLine("Running service...");
                        Console.WriteLine("Press any key to exit.");
                        Console.ReadKey();
                        svc.Stop();
                        break;
                    case "-i":
                    case "-u":
                        var ins = new AssemblyInstaller(typeof(Program).Assembly.Location, new string[0]) {
                            UseNewContext = true
                        };
                        if (args[0] == "-i")
                            ins.Install(null);
                        else
                            ins.Uninstall(null);

                        ins.Commit(null);
                        break;
                    case "-s":
                        new ServiceController(PublicName).Start();
                        break;
                    default:
                        Console.Write(@"Unknown switch. Use one of these:
            -c      Console: use for test run
            -i      Install service
            -u      Uninstall service
            -s      Start service
            ");
                        break;
                }
            } else {
                Log = LogToFile;
                RotateLog();
                ServiceBase.Run(new Service());
            }
        }