Monday, April 6, 2015

Run exe as a service

Trick to run an exe as a window service:

1. Install rktools.exe (Windows Resource Tool Kit). Download it from
http://www.microsoft.com/en-us/download/confirmation.aspx?id=17657

2. At a MS-DOS command prompt type the following command:
"path\INSTSRV.EXE" My Service "path\SRVANY.EXE"
Example:
"C:\Program Files (x86)\Windows Resource Kits\Tools\Instsrv.exe" SERVICENAME "C:\Program Files (x86)\Windows Resource Kits\Tools\Srvany.exe"

To verify if the service is created correctly, check the registry to verify that the ImagePath value under:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SERVICENAME

is set to point to SRVANY.EXE. If this is not set correctly, the service will stop and it will show an error "The service name failed to start."

3. From the above registry select newly created service and from the Edit menu, click Add Key. Type the following and click OK:
Key Name: Parameters

4. Select the Parameters key. From the Edit menu, click New - Add String Value. Type the following and click OK:
Value Name: Application
Data Type : REG_SZ
String : <path>\<application.ext>
where <path>\<application.ext> is the drive and full path to the executable application including the extension (i.e. C:\MyApp\MYUTILITY.exe)

Close Registry Editor.

Note: By default, a newly created service is run automatically when the system is restarted. To change this setting open services.msc from RUN command and select the service properties and change it's startup type accordingly.

Thank You
Pradeep Kumawat

No comments:

Post a Comment