create windows service


To remotely create and start a service from the command line, you can use the SC tool (Sc.exe) included in the Resource Kit.

Although you can use the Netsvc.exe and Instsrv.exe tools to start a service on a remote computer, these tools do not give you the ability to remotely create a service.

Note The Srvinstw.exe tool is the graphical user interface (GUI) version used to create remote services. Srvinstw.exe is not a command-line tool.

You can use Sc.exe to help develop services for Windows. Sc.exe, which is provided in the Resource Kit, implements calls to all of the Windows service control application programming interface (API) functions. You can set the parameters to these functions by specifying them on the command line. Sc.exe also displays service status and retrieves the values stored in the status structure fields. The tool also lets you specify the name of a remote computer so that you can call the service API functions or view the service status structures on the remote computer. 

Sc.exe also allows you to call any of the service control API functions and vary any of the parameters from the command line. The advantage to this is that it provides a convenient way to create or configure the service information in the registry and the Service Control Manager database. You do not have to configure the service by manually creating entries in the registry and then restarting the computer to force the Service Control Manager to update its database. 

Sc.exe uses the following syntax: 

Syntax1 (use Syntax1 to run Sc.exe)
sc [Servername] Command Servicename [Optionname= Optionvalue...]
Syntax2 (use Syntax2 to display help information, except for the query command)
sc [Command]