Reputation: 4527
I want to be able to develop a windows service which is capable of running multiple instances each with different parameters. Ideally I want to be able to maintain these parameters in a browser based control panel.
I have written a control panel in C# which saves the config data to an XML file. From this I want to be able to configure the number of services to run, and what their parameters should be. I want to be able to dynamically add and remove instances of the service as required.
My questions are: 1) Is this even possible? 2) Can I start a service with specific properties, from the control panel? (Maybe by using "NET START" with command line parameters?
[Edit] I just saw something online regarding the ServiceController class; can this be used to add and remove instances of a service as well as start/stop services? [/Edit]
Thanks for any help
Upvotes: 3
Views: 969
Reputation: 437684
Edit: My initial answer was factually wrong.
You can use command line parameters, either with NET START
(which however will only accept parameters starting with a backslash) or with SC START
(which will accept anything as a parameter).
You cannot start a service with dynamically chosen command line parameters. Parameters can also be specified at service registration time, in which case they remain constant thereafter.
However, starting multiple instances of a service sounds like the wrong idea. There is nothing stopping you from making just one instance of the service that you configure at runtime by communicating with it (e.g. with ServiceController.ExecuteCommand
), which is what you should do IMHO.
To communicate with a service, see for example How to communicate with a windows service from an application that interacts with the desktop? and How to create and communicate with a C++ Windows Service in Visual Studio 2010?
Upvotes: 3