Icon macro to put the system to sleep with one click

Philip Gross 0 Reputation points
2024-01-15T17:04:58.98+00:00
I am using Microsoft Windows 11 Pro (Beta).  I use the "Hello" feature with a Logitech Brio webcam.

I see that the "hibernate" option in Windows 11 Pro (Beta) is gone.  That's a good thing.

I have been trying the "Dynamic Lock" in Windows 11 Pro (Beta) feature with my iPhone 14 Pro MAX with limited success - the Bluetooth connection/reconnection required is not stable.  There are also folks who don't carry a smartphone everywhere with them at home or at the office, so automatically putting the system into sleep mode using Dynamic Lock is not available.  It takes three clicks to invoke sleep mode in that situation.  Yes, I am lazy, like all of us with various tools at hand, but it seems to me a desktop App could be made available where one click on the icon would put the system into sleep mode.  

I have found the following instruction set that can be used to create such a micro, namely:

  powercfg -hibernate off 

  rundll32.exe powrprof.dll,SetSuspendState 0,1,0

I suspect the first line is no longer useful since "hibernate" has been withdrawn.

Now I need help in creating the appropriate macro that can be run as an icon on the desktop, or applied to a programmable key on a keyboard such as the Microsoft Bluetooth Keyboard currently available.  While I started playing with these toys in 1962, this process is now beyound my capability so I am seeking help from this forum, please.
Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Pavlo Zinchenko 45 Reputation points
    2024-01-16T12:33:29.6933333+00:00

    Try the following instruction:

    1. Create a New Shortcut: Right-click on your desktop. Select New > Shortcut.
      User's image
    2. Input Command: In the location field, type rundll32.exe powrprof.dll,SetSuspendState 0,1,0. Click Next.
      User's image
    3. Name the Shortcut: Give your shortcut a meaningful name, like "Sleep Mode".
      User's image Click Finish to create the shortcut.
    1 person found this answer helpful.

  2. Kefas James Lungu 240 Reputation points
    2024-12-10T18:10:39.1766667+00:00

    Hello @Philip Gross ,

    powercfg /hibernate is still available, but it doesn't do what you want it to do.

    What it does:

    This command enables the hibernation feature on the system, it configures the system to allow hibernation. Without this, the hibernate option is unavailable.

    Which means it should be on, not off the way your command says.

    Secondly, it should be run once, not always running it if you want to hibernate your computer.

    Your second command:

    rundll32.exe powrprof.dll,SetSuspendState 0,1,0
    

    This command should work, if hibernation is enabled, however Microsoft doesn’t officially encourage using rundll32.exe commands for power management in modern systems, as it can behave inconsistently across versions.

    What I recommend:

    There are 2 options, depending on what you want.

    • Hibernate
    • Sleep

    Hibernate:

    Open your command prompt as an admin and run:

    powercfg /h on
    

    Then, Create a New Shortcut: Right-click on your desktop. Select New > Shortcut, in the place where you need to input the command, use:

    shutdown /h /t 0
    

    / t 0 determins the time in secons, change it as you please, the default is 30.

    Then, click next and give it a name like Hibernate or something.

    Sleep:

    To the best of my knowledge, there is no way you can put your computer to sleep with the powercfg command. So, we now turn to PowerShell.

    Kindly note: creating a shortcut with this command is not possible, but there is a work around. So do the following:

    1. Create a *.ps1 file, where * is the name of your script. For example: sleep.ps1.
    2. Open your file with notepad, or whatever text editor you wish, and put this in it:
    Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Application]::SetSuspendState('Suspend', $false, $false)
    
    1. Save it and exit.

    But if you want to create a shortcut, do the following after creating your script:

    1. Right-click on your desktop or desired location.
    2. Select New > Shortcut.
    3. In the shortcut location field, enter:
    powershell -ExecutionPolicy Bypass -File "C:\path\to\SleepScript.ps1"
    

    Execution Policy: The -ExecutionPolicy Bypass ensures the script runs without policy restrictions.

    Replace C:\path\to\SleepScript.ps1 with the full path to your script. 4. Click Next, name the shortcut Sleep or whatever, and click Finish.

    Now, you can run it whenever you want.

    I hope this helps, and don't forget to drop a comment if you are not clear, or still need help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.