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,663
  • 46
  • 140
  • 214
  • You mean you want your default to be hibernation? Also, take a look at this question: http://superuser.com/questions/189008/hibernate-from-start-menu-without-disabling-hybrid-sleep – Tobias Plutat May 09 '11 at 16:24
  • 1
    @studiohack: Hibernation is **not** hybrid sleep. :( I want my standby and hibernate option to **both** be there and *occasionally* choose hybrid sleep, not the other way around... is this really a dup? – user541686 May 09 '11 at 16:34
  • The question still reads like a duplicate...You're asking to have both sleep and hibernate options on the Start menu, correct? – studiohack May 09 '11 at 16:42
  • @studiohack: Yes, I'm asking for both sleep and hibernate to be there, and I want to somehow choose a third "hybrid sleep" option if I need to. I do **not** want to change the meaning of "sleep" to mean "hybrid sleep", which is the only mechanism I can find that's allowed in Windows. – user541686 May 09 '11 at 16:43
  • @Downvoter: Care to comment? – user541686 May 09 '11 at 16:59
  • @Mehrdad - Out of curiosity, why do you not like hybrid sleep as a default? The only technical down-side to it is that it takes a little longer to go to sleep, and temporarily requires a bit of space on your hard drive. – Iszi May 09 '11 at 17:22
  • @lszi: Because like you said, it takes a long time to sleep, and I use a laptop. I don't want to wait ~30-40 seconds for it to sleep when I want it to sleep, I want it to take like ~3. But occasionally I'm willing to wait, because I have time and want to protect my data, hence this question. – user541686 May 09 '11 at 17:37
  • @Mehrdad - I'm sure there's a workaround for this somehow. It's probably not something Microsoft supports, but I'll see about digging into it some more when I get home and have a Win7 machine in front of me. – Iszi May 09 '11 at 17:46
  • @lszi: Haha okay thanks! (My idea was to write a program to switch and then switch back the settings, but that seems pretty hacky... can't think of a better way though.) – user541686 May 09 '11 at 18:03
  • @Downvoter #2: Care to comment? – user541686 May 10 '11 at 03:06
  • @Mehrdad - Yeah, I was thinking of a Batch file or PowerShell script. I think "Hacky" is just a part of some of our natures here. Still trying to find the proper Registry key for this. – Iszi May 10 '11 at 20:14
  • @lszi: I do have an idea of how this would work if I was trying to change the system settings (shouldn't be too hard with the [Power API](PowerEnumerate)) but I was trying to avoid that... though I guess there might not be a better solution. :\ – user541686 May 10 '11 at 20:24

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,663
  • 46
  • 140
  • 214
  • There has *got* to be an easier way to do this. I'm thinking a few lines in a batch file. Still "hacky" maybe, but probably a bit more trim. Trick is to find where the setting is stored. – Iszi May 19 '11 at 04:30
  • @lszi: You indeed *can* do this with `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. :) – user541686 May 19 '11 at 04:44
-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
  • 3
  • 2
  • How does creating my own plan help? There's still only two options I can seen in the start menu -- one hibernate, one sleep (standby). No hybrid sleep. – user541686 May 09 '11 at 16:35