Using sc.exe
To communicate with the Service Control Manager, you can use a command-line tool called sc.exe
. To register our executable as a service, we'll use its create
command. Every service gets a behind-the-scenes short name such as testsvc
. Specify the new name as the first parameter to create
. The binPath
parameter sets the path to the executable. Be sure that the equal sign has no spaces before it and one after it. Follow this convention with all sc.exe
parameters that use an equal sign.
sc create testsvc binPath= "C:\WindowsService1.exe"
After running this command, you'll see the new service in the services management console (services.msc
) amongst the other installed services. Yours will show up as testsvc
. It won't be started yet for you. You'll have to start it manually, either through the services management console or with sc.exe
's start
command.
sc start testsvc
You'll always have to start your service the first time. However, you can change how it starts from then on. For...