Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)?

share|improve this question
2  
rundll32.exe PowrProf.dll,SetSuspendState is not recommended. It is dangerous. (Because it corrupts the stack, as it does not comply with the function signature demanded by Rundll32. Then unforeseeable bad things may happen, as Raymond Chen warns…) –  accolade Feb 20 '13 at 22:30
1  
============== ================== ====================== =================== =============== ============ SOLUTION !! ============ ====================== ================== ========= ========== ================= ==================== powercfg -h off & start /min "" C:\WINDOWS\System32\rundll32.exe PowrProf.dll,SetSuspendState 0,1,0 & ping -n 3 127.0.0.1 > nul & powercfg -h on & exit –  Afwe Wef Sep 10 '13 at 9:55
    
@AfweWef: Why don't you post that as an answer instead of a comment? –  accolade Mar 15 at 9:26
add comment

9 Answers

up vote 11 down vote accepted

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!

share|improve this answer
2  
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 –  Eric L Jul 24 '10 at 16:24
    
This is the solution that I ended up using. as it supports the hybrid sleep. –  Eric L Oct 16 '10 at 15:06
    
+1 This feels dirty but it works. I had to change the last Send part to: "Send, {RIGHT}{RIGHT}s". BTW I almost gave you a -1 for recommending to uninstall AHK, as that would be unforgivable :) –  demoncodemonkey Apr 22 '11 at 8:33
    
I also added this to the start of the script to ensure the commands go to the desktop window, and prevent them getting lost: WinActivate, ahk_class Progman –  demoncodemonkey Apr 24 '11 at 8:14
    
+1 to demoncodemonkey for threatening -1 on uninstalling AHK. –  dblanchard Jun 4 '11 at 1:01
show 3 more comments

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

share|improve this answer
3  
whoa nice! +1... –  studiohack Sep 15 '10 at 3:38
6  
This is great but where's the one for Sleeeeeeeeeeeeep –  demoncodemonkey Apr 22 '11 at 8:22
6  
Standby shortcut put my Win7 machine to hibernate :( –  buffer Jul 13 '11 at 15:12
4  
@demoncodemonkey: Standbyyyyyyyyyyyyy = Sleeeeeeeeeeeeep :) –  Răzvan Panda Mar 1 '12 at 12:22
5  
Apparently it does not: superuser.com/a/331545/21887 So it is considered dangerous to use this method and not recommended. (It corrupts the stack.) –  accolade Jun 20 '12 at 19:07
show 4 more comments

See the free utility of Wizmo, which can do very many things.
The command you're looking for is probably:

wizmo standby

share|improve this answer
    
Wizmo looks pretty cool! Almost makes me wish I wasn't a mac fanboy –  trolle3000 May 28 '10 at 20:13
    
The utility doesn't need to be installed. Nice simple tool. –  Artur Carvalho Jun 29 '11 at 0:12
2  
wizmo.exe quiet standby suppresses arguably annoying beeps by wizmo.exe. –  accolade Jun 20 '12 at 18:59
add comment

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

If you've never run a PowerShell script before, you'll want to first run

Set-ExecutionPolicy RemoteSigned

to enable script running. This only has to be run once.

share|improve this answer
add comment
psshutdown -d

using the Command Line tool PsShutdown from Sysinternals' PsTools [download].

(You might prefer this solution if you already have downloaded PsTools, it's pretty widely used. Other than that, this approach is equivalent to using wizmoquiet standby.)

Source: http://superuser.com/a/331545/21887

share|improve this answer
add comment

to disable hibernate mode you need to use

powercfg -h off

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

[EDIT]

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.

share|improve this answer
    
This also disables hybrid sleep, so it kinda defeats the purpose –  Eric L Sep 14 '09 at 10:22
    
rundll32 powrprof.dll,SetSuspendState hybrid sleep still put the computer into hibernation. thanks for the idea. –  Eric L Sep 15 '09 at 10:09
add comment

Make a bat file, where 600 is delay in seconds.

ping -n 600 -w 1 127.0.0.1 > nul

powercfg -h off

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

share|improve this answer
    
Great way to put the computer to sleep, and very easy to send someone else who wants to have sheduled sleep. –  Maurycy Zarzycki Oct 31 '11 at 23:10
    
Creative answer! –  Bob Apr 30 '12 at 15:06
add comment

If you're competent with compiling a .NET program the following command will do this

System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, 
                                                 false,   /* force */
                                                 true     /* disableWake */);

Note: You do not need to disable hibernation as is required by the rundll32 powrprof.dll,SetSuspendState command. You can also use PowerState.Hibernate which will hibernate the machine if you want.

You could easily compile an EXE with this command with any version of Visual Studio. Just create a console application and add a reference to the System.Windows.Forms DLL.

share|improve this answer
    
Wizmo cited above basically has already done this - using it seems like the equivalent. And it's written by Steve Gibson and free, so probably better than what I'd get hand coding the same thing! –  stevemidgley Jun 9 '11 at 0:03
    
+1. Looking for something like this here superuser.com/q/310045/84229 –  buffer Jul 13 '11 at 15:18
add comment

I've been using this SLEEP.EXE utility for years. It works well, and you don't have to remember what arguments to give it for suspend mode (its default form of "sleep").

share|improve this answer
add comment

protected by Community Jun 3 '11 at 20:15

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.