Parameters for created services have some peculiar formating issues, in particular if the command includes spaces or quotes:
If you want to enter command line parameters for the service, you have to enclose the whole command line in quotes. (And always leave a space after binPath=
and before the first quote, as mrswadge pointed out)
So, to create a service for the command PATH\COMMAND.EXE --param1=xyz
you would use the following binPath parameter:
binPath= "PATH\COMMAND.EXE --param1=xyz"
^^ ^
|| |
space quote quote
If the path to the executable contains spaces, you have to enclose the path in quotes.
So for a command that has both parameters and a path with spaces, you need nested quotes.
You have to escape the inner quotes with backslashes \". The same holds if the parameters themselves contain quotes, you will need to escape those too.
Despite using backslashes as escape characters, you do not have to escape the regular backslashes contained in the path. This is contrary to how you normally use backslashes as escape characters.
So for a command like
"PATH WITH SPACES \COMMAND.EXE" --param-with-quotes="a b c" --param2
:
binPath= "\"PATH WITH SPACES \COMMAND.EXE\" --param-with-quotes=\"a b c\" --param2"
^ ^ ^ ^ ^ ^ ^
| | | | | | |
opening escaped regular escaped escaped closing
quote quote backslash closing quotes quote
for for in quote for for
whole path path for path parameter whole
command command
Here is a concrete example from the SVNserve documentation, which shows all special cases:
sc create svnserve
binpath= "\"C:\Program Files\CollabNet Subversion Server\svnserve.exe\" --service -r \"C:\my repositories\" "
displayname= "Subversion Server" depend= Tcpip start= auto
(linebreaks are added for readability, do not include them)
This would add a new service with the command line "C:\Program Files\CollabNet Subversion Server\svnserve.exe" --service -r "C:\my repositories"
.
So in summary
- space after each sc parameter:
binpath=_
, displayname=_
and depend=_
- each sc parameter that contains spaces must be enclosed in quotes
- all additional quotes inside the binpath are escaped with backslashes: \"
- all backslashes inside the binpath are not escaped
binPath= "c:\abc\def.exe /Param1=ghi"
seems like the right idea. Do the backslashes need to be escaped (i.e. "c:\\abc\\...")? Worst thing, you could directly edit the Registry value afterwards if SC.EXE can't do it. – ewall