How to install a Windows service using command line ?
1>> Make a build of the service project then go to bin directory and copy required build files from either of the directory Release / Debug.
2>> Service will be in .exe file. This should be installed now, by using a command line as below –
Copy blow one to bat file , name it as install.bat.
c:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
InstallUtil.exe "E:\test\testservice.exe"
pause
Run install.bat to install the service.
3> To uninstall there are two ways –
a)
c:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
InstallUtil.exe –u "E:\test\testservice.exe"
pause
b)
sc delete <serviceName>
pause
Some time using point number 3.a , it is required to restart the windows machine so better to use the point 3.b.
Note- if you struck with the service which is already installed then you can kill that process , either using command line or ctrl+Alt+del select service and kill the process.