自动启动Windows服务上安装 [英] Automatically Start Windows Service on Install
问题描述
我有一个Windows服务和MSI安装(安装项目)它。安装项目具有自定义操作的安装和卸载用的args /安装/卸载分别
我想立即启动安装后的服务。我所有的服务确实是启动一个过程。如果该服务被停止,它确实 process.Close();
我试图做
VAR SC =新的ServiceController(MyProcess);
sc.Start();
这个过程开始,但该事件日志消息说该服务已启动不显示。当停止我得到的错误错误停止处理信息:System.InvalidOperationException:没有过程与此对象相关联
如果我不使用服务控制器启动和使用SERVICES.MSC相反,它可以作为停车时预期。
有没有办法让这个过程立即开始,并有我的起动/停止按预期的方式工作?
解决方案最后我采取了不同的方法,刚开始运行的进程,而不是试图保住前一次启动
I have a Windows service and an MSI installer (setup project) for it. The setup project has custom actions for install and uninstall with args of /install and /uninstall respectively.
I would like the service to start immediately after the install. All my service does is starts a process. When the service is stopped, it does process.Close();
.
I have tried doing
var sc = new ServiceController( "MyProcess" );
sc.Start();
The process starts, but the event log message saying the service has started doesn't show. When stopping I get the error Error stopping process: System.InvalidOperationException: No process is associated with this object.
.
If I don't use the service controller to start and use Services.msc instead, it works as expected when stopping.
Is there a way to have the process start immediately and have my start/stop methods work as expected?
I ended up taking a different approach by just getting the running process instead of trying to hold on to the one started before. Stopping the process then works just fine, and doesn't matter of the OnStart/OnStop methods are functioning "properly", because my inner process is starting/stopping like I need.
这篇关于自动启动Windows服务上安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!