1. 程式人生 > >windows服務安裝後立即啟動

windows服務安裝後立即啟動

true 添加 obj creat type屬性 lena strong nbsp false

置serviceProcessInstaller1控件的Account屬性為“LocalSystem

設置serviceInstaller1控件的StartType屬性為"Automatic"

private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)事件中,添加以下代碼:

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput 
= true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); string cmdstring = "sc start yourservicename"; //CMD命令 p.StandardInput.WriteLine(cmdstring); p.StandardInput.WriteLine("exit");

windows服務安裝後立即啟動