首頁  >  文章  >  後端開發  >  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