[python-win32] Windows Service, user activity and timed message box

Tim Golden mail at timgolden.me.uk
Tue Jan 27 15:03:38 CET 2009

Ferdinand Sousa wrote:
> Greetings:
> I wanted some help on the following topics:
> A] How do I set up a script to run as a service? Are there any prerequisites
> for this?

There are a few recipes in the cookbook. Here's one for starters:


> B] How do we check duration since last user activity -- Assuming that the
> screen is set to turn off/display a screensaver after a certain duration, I
> wouldn't mind checking if this has indeed occurred (I know how to use
> win32gui <http://win32gui.html/>.SystemParametersInfo to check if either of
> these has occurred). However, I would prefer to check the time elapsed since
> last user activity.

I don't know that there's a function to do that for
the entire system. GetLastInputInfo will do it for your
own application, but you'd probably need to install some
system hooks and roll your own to get this at system level.
(And that sounds like overkill for what you're after).

Perhaps a more precise description of your requirement would help?

> C] Timed message box -- Is there anyway I can set a timeout for a message
> box, so that if a user does not click some button within 'x' seconds, the
> message box closes of its own accord?

You can certainly implement your own dialog which mimics the message box
and which can do whatever it likes in its own message loop. The
alternative -- trying to post messages to a modal MessageBox queue --
would involve setting up a watchdog thread before you start the
messagebox which "finds" your message box and "presses its button".
Haven't tried it myself so there may be some gotcha I haven't
thought about.


More information about the python-win32 mailing list