RSS icon Home icon
  • How to disable Windows auto sleep in AC mode with code

    Posted on February 17th, 2023 admin No comments

    It can be annoying if you use your computer 24/7 and when you don’t interact with the desktop, your machine will go into sleep after a while. If you’re using the PC remotely, you cannot bring it back from sleep. You can also turn off sleep mode manually in Power & sleep under System preferences by changing the “When plugged in, PC goes to sleep after” setting to Never.

    Or even better, you can modify it with the PowerCfg utility by invoking the following command:

    powercfg /x -standby-timeout-ac 0

    This should be a simple set-and-forget option, but surprisingly, this setting can sometimes revert to its original value. I didn’t spend time trying to figure out why the value can change, instead I got my supervisor application watch and reset the value. Here’s how I figured out (debug) how to do it with API calls, and of course I’ll show you the working source code (C++, C#, Delphi).

    Read the rest of this entry »