程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 安裝完成Windows服務後自動打開,windows服務

安裝完成Windows服務後自動打開,windows服務

編輯:C#入門知識

安裝完成Windows服務後自動打開,windows服務


使用DOS進程開啟服務


設置serviceProcessInstaller1控件的Account屬性為“LocalSystem
設置serviceInstaller1控件的StartType屬性為"Automatic"

 

在服務器上添加安裝程序,在ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)事件中,添加代碼

 1 System.Diagnostics.Process p = new System.Diagnostics.Process();
 2 p.StartInfo.FileName = "cmd.exe";
 3 p.StartInfo.UseShellExecute = false;
 4 p.StartInfo.RedirectStandardInput = true;
 5 p.StartInfo.RedirectStandardOutput = true;
 6 p.StartInfo.RedirectStandardError = true;
 7 p.StartInfo.CreateNoWindow = true;
 8 p.Start();
 9 string Cmdstring = "sc start myservice"; //CMD命令
10 p.StandardInput.WriteLine(Cmdstring);
11 p.StandardInput.WriteLine("exit");

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved