首页  >  文章  >  后端开发  >  C#启动,停止Windows服务

C#启动,停止Windows服务

大家讲道理
大家讲道理原创
2016-11-10 10:13:491486浏览

这项API提供的实用功能常常用来管理应用程序中的服务,而不必到控制面板的管理服务中进行操作。

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

.net提供的API中,可以实现一句话安装与卸载服务

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


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn