windows服务安装后立即启动

置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");

 

posted @ 2017-12-01 09:53  过了这个村  阅读(437)  评论(0编辑  收藏  举报

正是因为短暂的生命中有那么多困难和不如意,死亡又在一旁窥视着我们,所以我们没有时间忧伤和叹息,我们必须认真地对待生命,去思考,去寻找。