Install, uninsttall and kill a Windows Service
After having set up new build environment I decided to note some tips on working with Windows services, for myself to remember, and for others to easily find needed steps. So, off we go.
To install a Windows service (in a Windows 7 environment):
1) Copy service files (including the .exe) to the folder C:\MyService
2) Open command prompt as Administrator
3) cd to C:\MyService
4) Install Windows service from commant prompt using installutil.exe:
C:\MyService>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\installutil.exe /serviceName="My Service" MyService.exe
To uninstall a Windows service:
1) Open command prompt as Administrator
2) cd to C:\MyService
3) c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /u /serviceName="My Service" MyService.exe
Sometimes, it can happen that Windows Service can not be stopped. It remains in status Stopping, and never stops actually. Then you would have to kill it:
1) Open command prompt as Administrator
2) sc queryex MyService. You will receive the following information:
SERVICE_NAME: MyService
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 4084
FLAGS :
3) taskkill /F /PID 4084
Мітки: configuration, services