winform scm服務

服務啓動

static void Main()
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new Service1()
    };
    ServiceBase.Run(ServicesToRun);
}

服務組件

serivice.cs 鼠標右鍵添加安裝程序

  • serviceProcessInstaller1 的賬戶設置成localsystem否則安裝時提示密碼登錄
  • serviceInstaller1服務的名稱配置

執行安裝

winform不支持服務帶參數安裝,只有用winapi添加帶參數的服務

 using (AssemblyInstaller installer = new AssemblyInstaller())
{
     installer.UseNewContext = true;
     installer.Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WindowsService.exe");
     IDictionary savedState = new Hashtable();
     installer.Install(savedState);
     installer.Commit(savedState);
}

刪除

using (AssemblyInstaller installer = new AssemblyInstaller())
{
    installer.UseNewContext = true;
    installer.Path = Application.ExecutablePath;
    in
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章