首页  ·  知识 ·  编程语言
Windows服务安装后自动启动
wfwup     .NET  编辑:dezai   图片来源:网络
在服务器上添加安装程序,在bprivate void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)/b事件

在服务器上添加安装程序,在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 myservice"; //CMD命令
p.StandardInput.WriteLine(Cmdstring);
p.StandardInput.WriteLine(
"exit");

即可在安装服务后立刻启动windows服务

 

注: 引用using System.Diagnostics;//调用Process

 

以上代码,亲测成功

本文作者:wfwup 来源:网络
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读