next up previous index
Next: Creating a Baseyear Database Up: How To Previous: How To   Index


Running a Python Script as a Windows Service

Solution found on this blog: http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html

Suppose you want to turn a script called myscript.py into a service.

  1. Install Win2K Resource Kit (or copy the 2 binaries instsrv.exe and srvany.exe). The full Resource Kit can be found here:
    http://www.microsoft.com/downloads/details.aspx?
    familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

  2. Run instsrv to install srvany.exe as a service with the name myscript:
    "C:\Program Files\Windows Resource Kits\Tools\instsrv" myscript "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"

  3. Go to Computer Management $ \rightarrow$ Services or Control Panel $ \rightarrow$ Administrative Tools $ \rightarrow$ Services and make sure myscript is listed as a service. Make sure the Startup Type is Automatic. Also make sure that the service has the right permissions to access applications in your computer by double clicking on myscript and going to Log On.

  4. Create a myscript.bat file in e.g. C:\pyscripts with the following contents:
    C:\Python23\python C:\pyscripts\myscript.py (replace Python23 with your Python version)

  5. Create new registry entries for the new service.

  6. Reboot your computer.

  7. Test starting and stopping the myscript service in Computer Management $ \rightarrow$ Services or Control Panel $ \rightarrow$ Administrative Tools $ \rightarrow$ Services


next up previous index
Next: Creating a Baseyear Database Up: How To Previous: How To   Index
info (at) urbansim.org