标签:
使用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");
标签:
原文地址:http://www.cnblogs.com/objecttozero/p/Auto_Windows_Service.html