Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if hibernation is available for a Windows user (with C++)

I know that one can call the following API to hibernate the system:

SetSuspendState(TRUE, FALSE, FALSE);

But is there any way to find out if "real" hibernation is available for the current Windows user?

Here's what I mean:

  1. If an admin calls:

    powercfg.exe /hibernate off
    

    the API above will put system into a Sleep mode. So how do you know (from a C++ program) that this will happen instead of hibernation?

  2. I'm not sure if there's a group policy that can prohibit a user from hibernating a computer connected to an Active Directory?

Edit I am aware of the (dated) IsPwrHibernateAllowed API. I find that it doesn't work: it still returns the same result even if powercfg.exe /hibernate off was called. Am I doing something wrong there? Can someone explain why IsPwrHibernateAllowed doesn't work for me?

like image 368
ahmd0 Avatar asked Oct 09 '22 06:10

ahmd0


1 Answers

Take a look at SYSTEM_POWER_CAPABILITIES structure that can be obtained with CallNtPowerInformation. Specifically, look at HiberFilePresent field.

like image 167
Violet Giraffe Avatar answered Oct 13 '22 12:10

Violet Giraffe