When creating a service with sc.exe how to pass in context parameters?

sympatric greg picture sympatric greg · Sep 8, 2010 · Viewed 430.5k times · Source

When creating Windows service using:

sc create ServiceName binPath= "the path"

how can arguments be passed to the Installer class's Context.Parameters collection?

My reading of the sc.exe documentation is that such arguments could only be passed on the end of binPath, but I have not found an example or been able to successfully do this.

Answer

Mhmd picture Mhmd · May 6, 2012
sc create <servicename> binpath= "<pathtobinaryexecutable>" [option1] [option2] [optionN]

The trick is to leave a space after the = in your create statement, and also to use " " for anything containing special characters or spaces.

It is advisable to specify a Display Name for the service as well as setting the start setting to auto so that it starts automatically. You can do this by specifying DisplayName= yourdisplayname and start= auto in your create statement.

Here is an example:

C:\Documents and Settings\Administrator> sc create asperacentral 
binPath= "C:\Program Files\Aspera\Enterprise Server\bin\Debug\asperacentral.exe" 
DisplayName= "Aspera Central" 
start= auto

If this worked you should see:

[SC] CreateService SUCCESS

UPDATE 1

http://support.microsoft.com/kb/251192