windows服务安装后立即启动

C#服务安装配置
本文介绍如何使用C#设置服务安装程序,包括将ServiceProcessInstaller1的Account属性设为LocalSystem,ServiceInstaller1的StartType属性设为Automatic,并在安装完成后通过CMD启动服务。

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

 

转载于:https://www.cnblogs.com/glzgc/p/7940539.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值