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.
- 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
- 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"
- Go to Computer Management
Services or Control Panel
Administrative Tools
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.
- 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)
- Create new registry entries for the new service.
- run regedt32 and go to the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlDataset\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
- Reboot your computer.
- Test starting and stopping the myscript service in
Computer Management
Services or Control Panel
Administrative Tools
Services
Next: Creating a Baseyear Database
Up: How To
Previous: How To
Index
info (at) urbansim.org