使用DOS进程开启服务
设置servicePRocessInstaller1控件的Account属性为“LocalSystem”
设置serviceInstaller1控件的StartType属性为"Automatic"
在服务器上添加安装程序,在ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)事件中,添加代码
1System.Diagnostics.Process p =newSystem.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;8p.Start();9string Cmdstring ="sc startmyservice";//CMD命令10p.StandardInput.WriteLine(Cmdstring);11 p.StandardInput.WriteLine("exit");