views:

39

answers:

2

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

EDIT

This isn't actually possible. However, you can edit the image path as per ho1's instructions.

A: 

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.

Reddog
There is so much garbage in App.Config these days that I don't want to put any configuration values that my production support team may actually touch in it.
Jonathan Allen
Wouldn't the production support team be the ones touching the installation parameters too? Why do you want to hide these set-once run-many settings in a place that isn't the norm? Particularly when the norm is so easy to work with...
Reddog
+1  A: 

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.

ho1
I am not asking about the username and password. I am asking about the box labeled "Startup Parameters".
Jonathan Allen
@Jonathan: Had forgotten that there was that field in the service dialog, changed my answer. Be aware that I'm not certain about this since it's things I've read or heard about rather than tried myself.
ho1
Thanks, that was what I was looking for.
Jonathan Allen