Exemple #1
0
        public static void Main()
        {
#if DEBUG
            ServiceLocator.Start();

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();

            return;
#endif

            var serviceOptions = GetServiceOptions();

            var installer = new WindowsServiceInstaller();
            if (installer.IsServiceExists(serviceOptions.ServiceName))
            {
                Console.WriteLine($"Service '{serviceOptions.ServiceName}' already installed. Stop and remove it.");

                installer.Stop(serviceOptions.ServiceName);
                installer.Uninstall(serviceOptions);
            }

            Console.WriteLine($"Install and start '{serviceOptions.ServiceName}' service");

            installer.Install(serviceOptions);
            installer.Start(serviceOptions.ServiceName);

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Exemple #2
0
        public Task <int> TryExecute(string[] arguments)
        {
            var state       = _PersistentInstallState.Load();
            var serviceName = (string)state[StateConstants.InstalledServiceName].NotNull();
            var installer   = new WindowsServiceInstaller(new UninstallConfiguration(serviceName))
            {
                Context = _InstallContextProvider.GetContext()
            };

            try
            {
                installer.Uninstall(state);
            }
            catch
            {
                try
                {
                    installer.Rollback(state);
                }
                catch
                {
                    // Do nothing here
                }

                _PersistentInstallState.Delete();

                throw;
            }

            return(Task.FromResult(0));
        }
        public void Can_Install_And_Uninstall_Service_Test()
        {
            var serviceName = "EmptyTestService";
            var installer = new WindowsServiceInstaller();

            var installResult = installer.Install(serviceName);

            Assert.IsTrue(installResult, $"cant install windows service: {serviceName}");

            var uninstallResult = installer.Uninstall(serviceName);

            Assert.IsTrue(uninstallResult, $"can't uninstall existing service: {serviceName}");
        }
Exemple #4
0
 private static void ManageInstallation(string[] args)
 {
     if (args[0] == "-?")
     {
         PrintUsage();
     }
     var name = args[1];
     var installer = new WindowsServiceInstaller(name, ServiceAccount.NetworkService);
     if (args[0] == "install")
     {
         installer.Install(new Hashtable());
     }
     else if (args[0] == "uninstall")
     {
         installer.Uninstall(new Hashtable());
     }
     else
     {
         PrintUsage();
     }
 }
 public void UninstallWith(WindowsServiceInstaller windowsServiceInstaller)
 {
     windowsServiceInstaller.Uninstall(new Hashtable());
 }