[python-win32] Catch system level events in python

Tim Roberts timr at probo.com
Mon Mar 1 03:16:41 CET 2010


You wrote:
>
>i am developing a windows service using python-win32.
>Now I am searching for a possibility to get a notification when a user is 
>trying to shutdown the system.
>In certain cases I need to cancel this shutdown,
>Does anyone knows how this could be done?

This is trickier than you might think.  Many shutdowns cannot be blocked.  For example, if battery power is critically low, you're going down, like it or not.  Further, if someone has their laptop set to hibernate when the close the lid, they're going to be really pissed off if your application blocks that and the battery expires.

On Vista and beyond, you can use ShutdownBlockReasonCreate to say "the system should not be shutdown for a while".

>Is it possible to catch system level events in python like in other 
>programming languages as for example C#:

Anything that can be done in C# can be done in Python.  Do you have a C# example you want to copy?

>http://mail.python.org/pipermail/python-win32/2008-January/006645.html

Is this code not sufficient for your needs?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.


More information about the python-win32 mailing list