I don't want my default sleep action to be hybrid sleep, but occasionally I want to use hybrid sleep.
How do I tell Windows, "go into hybrid sleep"?
I don't want my default sleep action to be hybrid sleep, but occasionally I want to use hybrid sleep.
How do I tell Windows, "go into hybrid sleep"?
I ended up making a hacky program that does this by temporarily changing the settings, but this really isn't what I was looking for... if someone comes up with a better solution, do post it. Otherwise, in case anybody finds this helpful, here's the code:
#include <tchar.h>
#include <Windows.h>
#include <PowrProf.h>
extern "C"
//int _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
int _tmain(int, LPTSTR[])
{
ULONG error = 1;
HANDLE hSem = CreateSemaphore(NULL, 1, 1, TEXT("Global\\HybridSleep.{A88FD0FD-4C24-23c0-88F6-B51A145FB444}"));
if (hSem != NULL && GetLastError() != ERROR_ALREADY_EXISTS)
{
GUID *guid,
allowHybridSleepGuid = { 0x94ac6d29, 0x73ce, 0x41a6, 0x80, 0x9f, 0x63, 0x63, 0xba, 0x21, 0xb4, 0x7e },
sleepSubgroupGuid = { 0x238C9FA8, 0x0AAD, 0x41ED, 0x83, 0xF4, 0x97, 0xBE, 0x24, 0x2C, 0x8F, 0x20 };
SYSTEM_POWER_STATUS sps;
if (GetSystemPowerStatus(&sps))
{
error = PowerGetActiveScheme(NULL, &guid);
if (error == ERROR_SUCCESS)
{
__try
{
ULONG index;
error = (sps.ACLineStatus ? PowerReadACValueIndex : PowerReadDCValueIndex)(NULL, guid, &sleepSubgroupGuid, &allowHybridSleepGuid, &index);
if (error == ERROR_SUCCESS && index <= 1)
{
__try
{
ULONG newIndex = 1 - index; //Opposite old value
error = (sps.ACLineStatus ? PowerWriteACValueIndex : PowerWriteDCValueIndex)(NULL, guid, &sleepSubgroupGuid, &allowHybridSleepGuid, newIndex);
if (error == ERROR_SUCCESS)
{
PowerSetActiveScheme(NULL, guid);
SetSuspendState(FALSE, FALSE, FALSE);
}
}
__finally
{
if ((sps.ACLineStatus ? PowerWriteACValueIndex : PowerWriteDCValueIndex)(NULL, guid, &sleepSubgroupGuid, &allowHybridSleepGuid, index) == ERROR_SUCCESS)
{ PowerSetActiveScheme(NULL, guid); }
}
}
}
__finally { LocalFree(guid); }
}
}
}
return error;
}
It performs the opposite of the current Hybrid Sleep setting.
powercfg
, but the trouble is the recovery: if for any reason you can't boot back, the setting will be changed permanently. I've found that if I modify my source code a bit, though, I can make it revert the setting before going into suspension, so that it always works. :)
May 19, 2011 at 4:44
In the control panel, you have the option to create your own power plan. You might be able to change the settings to your liking through that. You also might find more info here: http://windows.microsoft.com/en-us/windows7/Sleep-and-hibernation-frequently-asked-questions