Prevent service from being started twice

May 6, 2010 at 7:34 AM


I created a service like in the sample. It works really great.

The problem I have is that i want to be shure the service only runs once at a time. If I start my service .EXE again a second Service process is started. Is there a simple possibility to make shure that there can be only one instance of the service be running?



May 6, 2010 at 10:11 AM


the easiest way to determine, if a Service is already running is to register the service within the registry. Take a look at this documentation page.
Your service would have to check, if a service is already running, which can be read from the registry. If yes, just exit your second service andd all shall be fine.


Cheers, Peter