How to install a Window Service on server without visual studio tools

Posted on Posted in C#, Window Service

If need to install a window service on a server where Visual Studio is not installed or you don’t have Visual Studio tools then follow the steps below

1) You can find InstallUtil.exe at following directory
C:\Windows\Microsoft.NET\Framework64\v4.0.30319 (depending on system it could be a bit different but usually you will find under Framework > version)

2) Now open command prompt (run as admin)

3) copy following command and run it

Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe C:\ABCDevelopment\MyServiceWS.exe

Or

Go to InstallUtil folder first by typing
cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319\

then Type following command and press enter

InstallUtil C:\ABCDevelopment\MyServiceWS.exe

This will install window service for you.

In some case you might get an error like below

Exception occurred while initializing the installation:
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\ABCDevelopment\MyServiceWS.exe' or one of its dependencies. Operation is not s
upported. (Exception from HRESULT: 0x80131515).

To fix this go to your service.exe (in my case MyServiceWS.exe) file, click on properties and in General tab press unblock and save changes

Try installing again and this will fix the issue and install service.