The Windows Commandline: Services

Ever wanted to manipulate windows services from the command line (cmd.exe)? Now you can if you read this blog post :)

To get us started the first thing is to list the available services, we can do this using the sc query command, since it will spit out a lot of information we may want to pipe it through more or dump it into a file.

sc query | more

Every service has an internal name (you want to use this for the other commands), a display name and a status, the rest aren’t very useful for us. If we want to get some extra info about a specific service, like its binary file and dependencies you can use the following command.

sc qc <service name>

If you want to stop this service you can use ‘stop’ and to start it again ‘start’, very easy, isn’t it?
sc stop <service name>

Now comes the tricky part, to create a new service you use the ‘create’ option, the thing is that you have to give the parameters in the correct format for it to work, here is an example, notice the space between the ‘=’ and the value.

sc create test binpath= notepad.exe

Also you need to know that if the binary you are using for this isn’t prepared to work as a service Windows will kill it in about 30 seconds, because it’s expecting a signal to say that it started correctly, Microsoft provides a program called “SrvAny” available in the “Windows Server Resource Kit” which will help you run any application as a service, check this link for more details on this.

Finally, for modifying a service that already exist you can use “config” which takes in the same parameters from “create”.

Please leave a comment if you have any suggestions, also share the post if you found it useful!

Leave a Reply