404 Tech Support

Creating a shortcut to put your computer to sleep

I often put my computer at home to sleep when I walk away from it. With Windows 8, that’s a few clicks either way that you do it. I was hoping to find a faster way to do it, so I turned to scripting the process. That way I could just double-click a file or a shortcut on the Start Screen.

I first found the sleep command to run rundll32.exe powrprof.dll,SetSuspendState 0,1,0 but when I ran it, the command hibernated instead of sleeping. Apparently, that’s the only command available for sleep but it chooses to hibernate, if hibernation is enabled. If hibernation is disabled, then the computer will enter the sleep state after running that command.

To be sure, I just included turning hibernation off in my script with powercfg -h off.

[bash]
@echo off
Echo Sleeping… Zzz…
Powercfg -h off
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
exit
[/bash]

Now, I created that script as a .bat file and can double-click a shortcut to it on my Desktop whenever I want to put the computer to sleep. I can also pin it to the Start Screen. I even set up the shortcut with a keyboard shortcut so that when I’m on the Desktop, I can press Ctrl+Alt+S to put the computer to sleep.

Other commands that might be useful, you can just substitute lines 3 and 4:

Lock (or press Windows key + L)

[bash]Rundll32.exe User32.dll,LockWorkStation[/bash]

Hibernate

[bash]rundll32.exe PowrProf.dll,SetSuspendState[/bash]

Restart

[bash]shutdown.exe /r[/bash]

Shutdown

[bash]shutdown.exe /s[/bash]

Now, I have an easy shortcut on the desktop and Start screen to click to put the computer to sleep. That should be a bit more convenient.