Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Windows service from executable

Is there any quick way to, given an executable file, create a Windows service that, when started, launches it?

like image 731
German Latorre Avatar asked Aug 27 '10 07:08

German Latorre


People also ask

How do I create a Windows Service from the command line?

The SC Create command uses the following format: sc create serviceName binpath= "path\to\service-wrapper-7.4.exe" optionName= optionValue ... where: create is the command to be run by SC (this command name is mandatory to create a service).


1 Answers

To create a Windows Service from an executable, you can use sc.exe:

sc.exe create <new_service_name> binPath= "<path_to_the_service_executable>" 

You must have quotation marks around the actual exe path, and a space after the binPath=.

More information on the sc command can be found in Microsoft KB251192.

Note that it will not work for just any executable: the executable must be a Windows Service (i.e. implement ServiceMain). When registering a non-service executable as a service, you'll get the following error upon trying to start the service:

Error 1053: The service did not respond to the start or control request in a timely fashion.

There are tools that can create a Windows Service from arbitrary, non-service executables, see the other answers for examples of such tools.

like image 177
Sergii Pozharov Avatar answered Sep 21 '22 03:09

Sergii Pozharov