コード例 #1
0
ファイル: Program.cs プロジェクト: zaigr/epam-mentoring-a2
        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();
        }
コード例 #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));
        }
コード例 #3
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}");
        }
コード例 #4
0
ファイル: Runtime.cs プロジェクト: danryd/Tarro
 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();
     }
 }
コード例 #5
0
 public void UninstallWith(WindowsServiceInstaller windowsServiceInstaller)
 {
     windowsServiceInstaller.Uninstall(new Hashtable());
 }