Saturday, January 31, 2009

How to call a program as Windows service

It's really easy to call a program as a Windows service.
In order to proceed, you firstly need two programs: instsrv.exe and srvany.exe. These programs are produced by Microsoft and are parts of Windows Resource Kit Tools.

To call a program as a new Windows service, follow this procedure:
  1. Create a new directory, let's say winsrv, on drive c
  2. Store both instsrv.exe and srvany.exe on that directory
  3. Open a DOS window
  4. Type: cd /d c:\winsrv
  5. Type: instsrv "service name" c:\winsrv\srvany.exe
  6. Exit from DOS window
  7. Open regedit
  8. Navigate to this key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name
  9. Add a new key: Parameters
  10. Under the key Parameters, add these three string values: Application AppDirectory AppParameters
  11. Set the AppDirectory value to the directory where the program is stored into
  12. Set the Application value to the program name
  13. Set the AppParameters value to the command line parameters passed in program invocation
NOTE
In order to run the specified program, you may provide additional authentication information. This can be accomplished specifying log on parameters in the service properties.

To remove the new service, just follow this procedure:
  1. Open a DOS window
  2. Type cd /d c:\winsrv
  3. Type instsrv "service name" remove

1 comment:

Perfect Beauty said...

How can I get data from database to put into a dataset in a window service?