Video timeout on XP and Vista (power management)

By Robert Ellison. Updated on Sunday, May 3, 2020.

Video timeout on XP and Vista (power management)

I'm updating a screensaver so that it stops work once the monitor switches off. This seemed like a really simple requirement but it took some time to find an API that works on both XP and Vista.

My first attempt was ReadPwrScheme(). The documentation suggests using a different method on Vista - it should say so more strongly because on Vista you get back some default information that bears no relationship to reality.

Next I tried CallNtPowerInformation(). This doesn't mention any alternatives but also doesn't work on Vista. I've added comments on both MSDN pages pointing to the answer.

GetCurrentPowerPolicies() is just the ticket - it returns a wealth of information including the video timeout on AC and battery power and works on both XP and Vista.

Pinvoke.net has all the structures required but not the actual function. I've just added the C# interop signature for GetCurrentPowerPolicies().

I can't believe how frustrating finding this information has been. If you've found this post I hope it saves you a couple of hours :).

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Video timeout on XP and Vista (power management) #code #win32 How to tell when the monitor is going to get switched off on XP and Vista (power management, Win32 for C#) )

Add Comment

All comments are moderated. Your email address is used to display a Gravatar and optionally for notification of new comments and to sign up for the newsletter.