Python Tips

  Article on Setting Up a Python Script as a ServiceApril 16, 2007 09:24

Grig Gheorghiu wrote this great article on turning a python script into a service:

1. Install Win2K Resource Kit (Windows 2003 Resource Kit for XP users)
2. Run instsrv to install srvany.exe as a service with the name myscript:
C:\Program Files\Resource Kit\instsrv myscript "C:\Program Files\Resource Kit\srvany.exe"
3. Go to Computer Management->Services and make sure myscript is listed as a service. Also make sure the Startup Type is Automatic.
4. Create a myscript.bat file with the following contents in e.g. C:\pyscripts:
C:\Python23\python C:\pyscripts\myscript.py
(replace Python23 with your Python version)
5. Create new registry entries for the new service.
run regedt32 and go to the

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\myscript entry

add new key (Edit->Add Key) called Parameters

add new entry for Parameters key (Edit->Add Value) to set the Application name

Name should be Application

Type should be REG_SZ

Value should be path to myscript.bat, i.e. C:\pyscripts\myscript.bat

Add new entry for Parameters key (Edit->Add Value) to set the working directory

Name should be AppDir

Type should be REG_SZ

Value should be path to pyscripts directory, i.e. C:\pyscripts


6. Test starting and stopping the myscript service in Computer
Management->Services.

 
 
Restricted access
Please sign in:
Username:
Password:
expire cookies