Passing argument to a windows service
Hi, I would like to create a service which would launch a command when I start it and an other command when I stop it. But when creating a service (using 'sc'), I can only associate it to ONE command. I don't understand how the windows services work to differentiate to 'stop' action from the 'start' action. I suppose that an argument is sent, but I can't find what is this argument, so I can't exploit it... Thanks in advance for your help!
July 21st, 2010 11:52am

Hi, Services are started and stopped in response to trigger events, http://msdn.microsoft.com/en-us/library/dd405513(v=VS.85).aspx These are handled in the .Net framework using the methods here, http://msdn.microsoft.com/en-us/library/aa983720(v=VS.71).aspx I would recommend designing your service to perform the start command with the OnStart method and the stop command to the OnStop command; however as a general design principal it does not sound like part of the application always needs to be available, so it may make sense to use a program or a script that takes a -start and a -stop argument. See http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx for more information about creating a service. -- Mike Burr
Free Windows Admin Tool Kit Click here and download it now
July 21st, 2010 5:01pm

Hi, Thanks for the post. As it is a more related to developing issue, please re-post a new thread to our MSDN Forum: http://social.msdn.microsoft.com/Forums/en-US/categories Thanks, MilesPlease remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
July 22nd, 2010 5:45am

Thanks for your answers!
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2010 2:54pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics