首页 > Windows开发 > 详细

windows服务安装后立即启动

时间:2017-12-01 10:39:01      阅读:208      评论:0      收藏:0      [点我收藏+]

置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服务安装后立即启动

原文:http://www.cnblogs.com/glzgc/p/7940539.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!