7.2. Running Any Program or Script as a Service


You want to run a program or script as a service. This is useful when you want a program to run continuously regardless if someone is logged in.


The following solutions install the Perl script monitor.pl as a service named MyMonitor.

Using a graphical user interface

  1. Open the Service Creation Wizard (srvinstw.exe ).

  2. Select Install a service and click Next.

  3. Select the target machine to install the service on and click Next.

  4. Enter MyMonitor for the service name and click Next.

  5. Enter the path of the srvany.exe executable and click Next.

  6. Select Service is its own process and click Next.

  7. Select the account to run the service under and click Next.

  8. Select the service startup type and click Next.

  9. Click Finish.

  10. Open the Registry Editor (regedit.exe).

  11. In the left pane, browse to the service's registry key by opening HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Services MyMonitor.

  12. Right-click on MyMonitor and select New Key.

  13. Enter Parameters and press Enter.

  14. Right-click on Parameters and select New String Value.

  15. Enter Application and press Enter twice.

  16. Enter the path to the Perl executable (e.g., c:\perl\bin\perl.exe) and click OK.

  17. Right-click on Parameters and select New String Value.

  18. Enter AppParameters and press Enter twice.

  19. Enter the path to the Perl script (e.g., c:\scripts\monitor.pl) and click OK.

  20. Open the Services snap-in.

  21. In the left pane, right-click on MyMonitor and select Start.

Using a command-line interface:

Run the following ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.