Share this question

Welcome to Teachnovice Q&A, where you can ask questions and receive answers from other members of the community.

This is a collaboratively edited question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Command to use to put computer to sleep (not hibernate)?

0 like 0 dislike
10,425 views

I want to put my Windows PC (Windows 7) into a sleep state via command line (so I can bind to macro button on keyboard).

The power button on the PC is setup to but the computer to sleep (but it's down on the floor and I'm too lazy to reach down) it exactly how I want it (sleeps using hybrid mode in case I loose power)

The sleep command on the shutdown menu also works.

most info I found says to use;

%windir%\system32\rundll32.exe PowrProf.dll, SetSuspendState 0,1,0

But this puts the computer in hibernate mode. I do have hibernate disabled but using hybrid sleep.

So, What is the command to use to put your computer to sleep (not hibernate)?

asked Nov 8, 2012 by anonymous  
retagged Apr 19, 2013

4 Answers

0 like 0 dislike
 
Best answer

I found a solution. I installed a freeware program called AutoHotKey and recorded the steps to invoke Start Menu -> Sleep into a script file. Then I complied the script file into a stand-alone executable SleepWin7.exe.

Now I simply run SleepWin7.exe to put my computer into hybrid sleep.

You may uninstall AutoHotKey if this is all you need it for.

Update: The above solution doesn't work when the user isn't logged in, i.e. Windows 7 Login Screen. (My computer wakes up at 4am every Sunday to perform weekly backup, which is done without user login.) In such case, the Wizmo program still works:

wizmo.exe quiet standby!
answered Nov 8, 2012 by anonymous  
Here is an AutoHotKey script (using keyboard); Send, {LWINDOWN}{LWINUP} WinWait, Start menu, IfWinNotActive, Start menu, , WinActivate, Start menu, WinWaitActive, Start menu, Send, {TAB}{UP}{RIGHT}s
This is the solution that I ended up using. as it supports the hybrid sleep
0 like 0 dislike

Hope you find these useful.

Shutdown %windir%\System32\shutdown.exe -s

Reboot %windir%\System32\shutdown.exe -r

Logoff %windir%\System32\shutdown.exe -l

Standby %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Standby

Hibernate %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Hibernate

answered Nov 8, 2012 by anonymous  
0 like 0 dislike

You can create a file with extension .ps1 (powershell) like "sleep.ps1" and write this:

Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState("Suspend", $false, $true)

I use this when I have something running and have to leave the pc and don't want to turn it off. So I change the script to look like this:

$secs = read-host "Enter minutes to wait until sleep";
$minutes= 60*$secs;
Start-sleep -s $minutes
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState("Suspend", $false, $true)

And now when I run it, I just enter the minutes I want to wait until sleep.

You can run this from the cmd line by writing powershell sleep.ps1.

answered Nov 8, 2012 by anonymous  
0 like 0 dislike

to disable hibernate mode you need to use

powercfg -h off

now, rundll32 powrprof.dll,SetSuspendState will put your station in stanby mode

Actually I can't setup for an hybrid sleep because I have a laptop (a state that is not available on mobile stations), for hybrid sleep you need to have hibernation enabled and some say that rundll32 powrprof.dll,SetSuspendState trigger the default sleep mode in your control-panel\power-management settings. please try if rundll32 powrprof.dll,SetSuspendState hybrid sleep give some results.

answered Nov 8, 2012 by anonymous  
...