Home  >  Article  >  Backend Development  >  C# starts and stops Windows services

C# starts and stops Windows services

大家讲道理
大家讲道理Original
2016-11-10 10:13:491526browse

The practical functions provided by this API are often used to manage services in applications without having to go to the management services of the control panel. In the API provided by

ServiceController controller = new ServiceController(“e-M-POWER”);      
controller.Start();      
if (controller.CanPauseAndContinue)      
{      
    controller.Pause();      
    controller.Continue();      
}      
controller.Stop();

.net, you can implement installation and uninstallation services in one sentence

if (args[0] == "/i")
 {
       ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
 }
 else if (args[0] == "/u")
 {
   ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
 }


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn