设置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 = "Net Start myservice"; //CMD命令
p.StandardInput.WriteLine(Cmdstring);
p.StandardInput.WriteLine("exit");
即可在安装服务后立刻启动windows服务
注: 引用using System.Diagnostics;//调用Process
设置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 = "Net Start myservice"; //CMD命令
p.StandardInput.WriteLine(Cmdstring);
p.StandardInput.WriteLine("exit");
即可在安装服务后立刻启动windows服务
注: 引用using System.Diagnostics;//调用Process
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/11/11/1601112.html,如需转载请自行联系原作者