How to: register service with SC command without losing quotes in binpath value

Registering a service on a Windows machine with SC command is rather straightforward process, and you may use /? to familiarize yourself with switches etc.

There is only one issue which you may run into – most of binaries which are being registered as a services on Windows machines reside in “C:\Program Files” or “C:\Program Files (x86)” so you should pass binary path with quotes. If you just run something like this:

sc create MyService binpath= "C:\Program Files (x86)\My Service\myservice.exe" displayname= "My Service"

Service will be successfully registered, but you lose quotes in binpath in this case. In order to preserve quotes in binpath following syntax should be used:

sc create MyService binpath= "\"C:Program Files (x86)\My Service\myservice.exe\"" displayname= "My Service""

In order to have quotes for path you put inside of parameter quotes so called “escaped quotes”. I guess following picture makes it all clear:


Source: HugoRune‘s answer on StackExchange to question “creating a service with sc.exe; how to pass in context parameters

Another hack or approach will be creating service as is, then adjusting parameters and/or binpath in respective section of registry:



1 Comment

  • Solarsails says:

    This is good to know, I’ certain this will come up some day. I put it in my notes.

    PS I thought the reference to your source was especially courteous. (That will probably come back around in your direction some day as well).

Leave a Reply

Your email address will not be published. Required fields are marked *