1

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"?


Note: I am not asking for the "sleep" option (standby) to be replaced with the hybrid sleep action. I need both to be available.

user541686
  • 23,629

2 Answers2

0

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.

user541686
  • 23,629
-1

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

w7pro
  • 692