[python-win32] How to invoke Python program from Windows service?

Harald Armin Massa[legacy] haraldarminmassa at gmail.com
Fri Jun 22 13:39:00 CEST 2012


Matt,

>
> Yeah, that was exactly my problem; I had no way to diagnose what was going on, and >needed a springboard to tell me what I needed to know in order to figure out what was >happening (or not).  I could verify that the script *worked*, since I could run it from a DOS >prompt without errors.  But when I ran it using CreateProcess (and ProcessStartInfo), I >didn't see it execute (since it would have created a file in its directory).
>
> However, your answer that I can write it directly with pywin32 intrigues me, especially since >I'd rather develop in Python anyway.  I'll go see what's involved in doing that.  Thanks for the >pointer!

>From my experiences with Python windows services some things to lookout for:

 - the "working directory" of the service is usually where the service
control programm resides; especially NOT your Python directory

- the path is usually the system path. It is not uncommon that Python
resides in a different path

- network drives are often not mapped for services, so make sure to
use UNC-paths

- some windows-system-dlls may have the same name as some of your
python-programm files (or, even worse, as some of the Python files of
any one of standard library or your used libraries). Windows usually
looks first into the current directory ... which may have unexpected
results when "import xxxx" loads xxxx.dll from windows, instead of
your xxxx.py

Best wishes,

Harald


-- 
LightningTalkMan
a brand of GHUM GmbH
Spielberger Straße 49
70435 Stuttgart
0173/9409607


More information about the python-win32 mailing list