[python-win32] How to find the current/last system state from Python

Tim Roberts timr at probo.com
Fri Jul 6 19:03:02 CEST 2012


prashant padaganur wrote:
>
> Thanks Tim. But when the system is in S0 state I want to read that information from the system.

You want to read WHAT information from the system?  Look, here is a
complete Python program that accurately tells you the current power state:

    print "The system is now in S0."

If you have a window (even a hidden window), you can grab the
WM_POWERBROADCAST message to learn when the system is about to leave S0,
and when the system is back in S0 after being in another state, but if
you are running, the system is in S0.  And that message doesn't tell you
which state you are going to or from.


> May be as suggested I can try getting the previous states from Windows event logger.

So, when you're in S0, you want to know what state we were in the last
time we were NOT in S0?  I'm not sure there's any reliable way to do
that without using a driver.  Kernel drivers get reliable messages on
each power state transitions that indicate both the old state and the
new state.  Even a user-mode (UMDF) driver can do that.  Perhaps that
would solve your issue.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list