Thursday, March 13, 2014

How to install a windows service in a server which doesn't have Visual Studio installed

If you have visual studio installed in a server, it would be easier to install a windows service, by using installutil.exe. However this have to be done from Visual Studio command prompt.

But how can you install if you don't have Visual studio command prompt in the server.

Below is the solution:

SC Create <Service name> binPath= "complete path of the exe file" DisplayName= "MyService"

ex:-  sc create MyService binPath= "C:\temp\Service1.exe" DisplayName= "MyTestService"

The service will be created and will be displayed in services.msc as MyTestService. If you right click and check the properties of the service, it will show the service name as MyService.

IMPORTANT:- Make sure you add a space after the "=" for the arguments.
Like binPath= "C:\temp\Service1.exe" DisplayName= "MyTestService". You can see the space marked in purple color. This has to be there to run the command successfully.

Otherwise, it doesn't even throw error and you will not have a clue of what is happening.

You can use SC Delete command to delete the service from the console.