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

63

44

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

Eric L

Posted 2009-09-11T10:16:21.267

Reputation: 1 365

5rundll32.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…) – Aaron Thoma – 2013-02-20T22:30:57.403

Answers

13

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!

Andy Lee

Posted 2009-09-11T10:16:21.267

Reputation: 156

you may need to right click and do 'Unblock' on the exe under 'Advanced' – Simon – 2014-07-15T01:53:45.280

3Here 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 – 2010-07-24T16:24:05.627

This is the solution that I ended up using. as it supports the hybrid sleep. – Eric L – 2010-10-16T15:06:44.697

+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 – 2011-04-22T08:33:35.457

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 – 2011-04-24T08:14:21.087

+1 to demoncodemonkey for threatening -1 on uninstalling AHK. – dblanchard – 2011-06-04T01:01:13.600

+1 Not the cleanest/ideal solution, since one would expect that there is a windows command-line feature to do the same, but it works like a charm. BTW: I have been looking allover for the Windows equivalent and all I found was this: C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0 - which doesn't do exactly the same. So thumbs up for a solution that works! – reSPAWNed – 2012-02-03T11:51:39.703

The ! in wizmo.exe quiet standby! enforces the StandBy even if applications object. quiet suppresses arguably annoying beeps by wizmo.exe. (In case someone wondered.) – Aaron Thoma – 2012-06-20T18:57:44.253

1

After switching to Windows 8, I'm now using NirCmd (very light weight) and it puts the computer to hybrid sleep; nircmd.exe standby more info can be found here -> http://www.nirsoft.net/utils/nircmd.html

– Eric L – 2013-04-06T18:25:57.740

73

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

Caution: rundll32.exe should not be used to launch powerprof.dll. Instead you should call SetSuspendState directly. This can be done using Powershell - create a file eg sleep.ps1, with the below contents.

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

Then run it using powershell -File C:\your-path\sleep.ps1. You may first need to run the command Set-ExecutionPolicy RemoteSigned to enable powershell scripts to run.

The above script causes a system suspend, which will either sleep or hibernate depending on your current hibernate setting. To change that setting from the command line, run powercfg -h off (or on) from the command line as administrator.

imoatama

Posted 2009-09-11T10:16:21.267

Reputation: 1 906

4whoa nice! +1... – studiohack – 2010-09-15T03:38:25.773

1+1 All of them needs to be executed from elevated command prompt in Windows 7 – IsmailS – 2011-04-11T05:16:41.503

9This is great but where's the one for Sleeeeeeeeeeeeep – demoncodemonkey – 2011-04-22T08:22:13.273

7Standby shortcut put my Win7 machine to hibernate :( – user – 2011-07-13T15:12:52.160

5@demoncodemonkey: Standbyyyyyyyyyyyyy = Sleeeeeeeeeeeeep :) – Răzvan Flavius Panda – 2012-03-01T12:22:12.057

2

Does powrprof.dll,SetSuspendState comply with the function signature demanded by Rundll32? Otherwise unforeseeable bad things may happen, as Raymond Chen warns

– Aaron Thoma – 2012-06-20T18:54:29.280

11

Apparently it does not: http://superuser.com/a/331545/21887 So it is considered dangerous to use this method and not recommended. (It corrupts the stack.)

– Aaron Thoma – 2012-06-20T19:07:15.483

2%windir%\System32\shutdown.exe -h to hibernate. – DonGar – 2012-10-29T05:40:50.127

1standby does not equal sleep on my system, it puts it in hibernation – Eric L – 2013-04-06T18:32:11.733

16

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

wizmo standby

harrymc

Posted 2009-09-11T10:16:21.267

Reputation: 306 093

Wizmo looks pretty cool! Almost makes me wish I wasn't a mac fanboy – trolle3000 – 2010-05-28T20:13:09.880

The utility doesn't need to be installed. Nice simple tool. – Artur Carvalho – 2011-06-29T00:12:05.780

2wizmo.exe quiet standby suppresses arguably annoying beeps by wizmo.exe. – Aaron Thoma – 2012-06-20T18:59:00.613

14

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:

$minutes = read-host "Enter minutes to wait until sleep";
$secs= 60*$minutes;
Start-sleep -s $secs

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 -File C:\your-path\sleep.ps1

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

Set-ExecutionPolicy RemoteSigned

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

Artur Carvalho

Posted 2009-09-11T10:16:21.267

Reputation: 1 617

Aren't your variables' names backwards? – Ullallulloo – 2016-08-15T20:28:21.703

11

With Sysinternals PsTools [download]:

psshutdown -d

using the Command Line tool PsShutdown.

(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: https://superuser.com/a/331545/21887

Aaron Thoma

Posted 2009-09-11T10:16:21.267

Reputation: 550

7

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").

jjlin

Posted 2009-09-11T10:16:21.267

Reputation: 12 964

SLEEP.EXE works for me, on Windows 7 Pro SP1. The parent page also lists many other useful-looking command line tools for Windows. Thanks, @jjlin! – CODE-REaD – 2016-09-11T20:40:15.017

6

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.

user8228

Posted 2009-09-11T10:16:21.267

Reputation:

rundll32 is not designed for calling SetSuspendState, so it gets wrong parameter values. That's why it always cause hibernation if you have not disabled it intentionally. – SergeyT – 2016-07-26T22:32:22.793

This also disables hybrid sleep, so it kinda defeats the purpose – Eric L – 2009-09-14T10:22:26.640

rundll32 powrprof.dll,SetSuspendState hybrid sleep still put the computer into hibernation. thanks for the idea. – Eric L – 2009-09-15T10:09:28.740

5

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

dim77x

Posted 2009-09-11T10:16:21.267

Reputation: 59

Don't use rundll32.exe to call SetSuspendState: it is not designed for that. See explanations here

– SergeyT – 2016-07-26T22:29:12.527

Great way to put the computer to sleep, and very easy to send someone else who wants to have sheduled sleep. – Maurycy – 2011-10-31T23:10:35.070

Creative answer! – Jane Panda – 2012-04-30T15:06:35.743

4

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.

Simon

Posted 2009-09-11T10:16:21.267

Reputation: 592

You don't even have to use Visual Studio to compile. Instead, the command-line compiler csc.exe could be used. It is already installed in all modern versions of Windows. – SergeyT – 2016-07-26T22:36:45.807

1Wizmo 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 – 2011-06-09T00:03:02.940

+1. Looking for something like this here http://superuser.com/q/310045/84229

– user – 2011-07-13T15:18:17.880