windows服务安装后立即启动

Posted 过了这个村

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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");

 

以上是关于windows服务安装后立即启动的主要内容,如果未能解决你的问题,请参考以下文章