A trick to create a service using SC.exe under Windows XP

One friend of mine suddenly found that Windows firewall service is no more present on his system.
He asked me to help him with command line string to create new service.
When I first tried to create a new test service on my machine I failed.

The handy tool sc.exe keeps showing help messages everytime when there are problems
with parsing command line options.
It does not show you which option was not formatted correctly.
The main trick is that after each option name you should place space symbol (” “) and
without this symbol the line cannot be parsed correctly.

So here is the correct example which create Windows firewall service with default
parameters:

 sc create "WINF" binPath= "c:\windows\system32\svchost.exe -k netsvc"


I think I know why space symbols are so mandatory for sc.exe.
Since each single substring in command line for sc.exe is separated by spaces it
is little bit easier to write a C code which parses the whole line.

But this is definitely not a way to write command line tools.

3 Responses to “A trick to create a service using SC.exe under Windows XP”

  1. hb says:

    bravo!! Found this tip after googling for 2 hours!! Thanks a lot! Microsoft, shame on you!! Such a huge hole and not any mention

  2. JP says:

    Thanks, this really helped me out.

  3. An says:

    About the comment above that there was problems with how the command line tool was written because of the supposed space issue, that is a problem with any command line tool that I am aware of, because if you are reading input parameters that are passed into the command line app, then anytime there is a space, that is interpreted as a new parameter and has to be parsed accordingly. As a developer who has written many command line tools, I think that comment is short sighted and misinforms, because that is a problem with the command shell as a whole, not with the utility per se. Having worked with the command line (cli) on numerous different operating systems for over 20 years now, this has always been an issue regardless of the command line app. Great tip though by the way to show people how to correctly handle parameters that need to have spaces in them. Just my $.02…

RSS feed for comments on this post. And trackBack URL.

Leave a Reply