views:

95

answers:

2

I wrote a temperature logger Python script and entered it as a scheduled task in Windows XP. It has the following command line:

 C:\Python26\pythonw.exe "C:\path\to\templogger.py"

It writes data to a file in local public folder (e.g. fully accessible by all who login locally).

So far, I was able to achieve this objective:
1. Get the task to run even before anyone logs in (i.e. at the "Press Ctrl+Alt+Del" screen)

But I'm having problems with these:
1. When I log in, log out, then log back in, the scheduled task is no longer active. I can no longer see it in the Task Manager's Processes tab. I suspect it closes when I log out.
2. I tried to set the task's "Run As..." property to DOMAIN\my-username and also tried SYSTEM, but problem #1 above still persists.

SUMMARY:
I want my program to be running as long as Windows is active. It should not matter whether anyone has logged in or out.

P.S.
I asked the same question in Super User, and I was advised to write it as a service, which I know nothing about (except starting and stopping them). I hope to reach a wider audience here at SO.

+3  A: 

http://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how

http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html

katrielalex
About the article at `agiletesting`, can I apply that to `exe`s compiled with `py2exe` as well?
Kit
@Kit: I should think so; you'd replace `myscript.bat` with `myexe-ifiedscript.exe`.
katrielalex
+2  A: 

Your scenario is exactly the required use case for a service, unfortunately tasks are ill suited for what you are looking to do. That said writing services in python is not a walk in the park either, to ease the pain here is a few links I have perused in the past:

http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html

http://mail.python.org/pipermail/python-win32/2008-April/007298.html

I used the second link in particular to create a windows scripts that was then compiled to a executable service with py2exe and installed with SrvAny.

ebt
Does your second link use Mark Hammond's [`pywin32`](http://sourceforge.net/projects/pywin32/) package?
Kit