开发者

Is it possible to programatically set the "Start Parameters" on a Windows Service at install time?

开发者 https://www.devze.com 2023-01-04 10:30 出处:网络
Is it possible to programatically set the \"Start Parameters\" on a Windows Service at install time? EDIT

Is it possible to programatically set the "Start Parameters" on a Windows Service at install time?

EDIT

This isn't actually开发者_如何学JAVA possible. However, you can edit the image path as per ho1's instructions.


Edit: I misunderstood the question so here's my new answer.

I think those parameters are only for using while actually starting the service manually from the services applet. I don't think those are an actual setting that are stored anywhere.

The closest thing to that would be to add some parameters after the service exe name in the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[YourService]\ImagePath 

You can use the ChangeServiceConfig API to change this (MSDN docs here, PInvoke here). I think you might also be able to change this as one of the settings of the Installer.Context property (described here), possibly called AssemblyPath or similar.

I'm not sure if parameters set this way might appear to the main function rather than the OnStart though (I think start parameters go to OnStart), so it might not be exactly what you're looking for but hopefully it'll give you some ideas.


If you're able to produce a deployment for each configuration and you want your parameters configured at "install time" (that is, once only and not per-start up) then perhaps you should simply use an App.config and some AppSettings.

0

精彩评论

暂无评论...
验证码 换一张
取 消