Monday, June 20, 2011

How to install a Windows service using command line ?

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.

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code