5

I have found a lot of info about how to shut down computer, put it in hibernation etc via the command line, however, any tips i have read about getting it to sleep as it does from the start-menu has so far not worked properly.

I would like a command that puts the computer in a light standby mode where a keypress would make the computer wake again, and not in hibernation. Does anyone know of this?

AFAIK, rundll32.exe powrprof.dll,SetSuspendState 0,1,0 does NOT put the computer to sleep / standby in all cases, and is as such not appropriate for my use...

Thanks, Araho

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Araho
  • 139
  • 1
  • 1
  • 5
  • In which cases does that command not put the computer to sleep? – Ry- Jun 15 '11 at 01:03
  • In my case, at least :P Well, it puts it into hibernation just like shutdown -h. I want the same kind of sleep as i get when i use the start-menu -> sleep. – Araho Jun 15 '11 at 01:07
  • Did you look at this: http://superuser.com/questions/42124/how-can-i-put-the-computer-to-sleep-from-command-prompt-run-menu-in-windows-vista (The second answer.) You could turn off hibernation temporarily, then turn it back on upon awakening... – Ry- Jun 15 '11 at 01:11

4 Answers4

8

Thanks to @minitech, I finally got it working. Leaving this here for all who want to know the answer, and giving two examples, one in direct command-line and one in Visual C#:

Add elevated priveleges to your app:

  • In other words, in command-line, start it as Administrator.
  • In Visual C#, which is what I'm using, add a manifest file to the project, and edit the "requestedExecutionLevel"-element to the following:

Then run the following commands:

  • In commandline:

    1. "powercfg -hibernate off" - This shuts off the hibernation mode possibility.

    2. rundll32.exe powrprof.dll,SetSuspendState 0,1,0 - This makes the computer sleep.

    3. powercfg -hibernate on - This allows the hibernation mode to again be activated.

  • In Visual C#, use the following code:

    1. System.Diagnostics.Process.Start("powercfg", "-hibernate off"); // Turn off hibernation mode setting.

    2. System.Diagnostics.Process.Start("rundll32.exe", "powrprof.dll,SetSuspendState 0,1,0"); // Send the computer to sleep

    3. System.Diagnostics.Process.Start("powercfg", "-hibernate on"); // Turn on hibernation mode setting after waking computer.

It is very important to remember to add Administrator priveleges, or it will make the computer hibernate, which takes forever.

Araho

Araho
  • 139
  • 1
  • 1
  • 5
1

STANDBY (SLEEP) with CMD (command prompt or .bat), doesnt work in Windows 10.

Use QUICK SLEEPER.

T.Todua
  • 53,146
  • 19
  • 236
  • 237
0

Tried and tested NirCMd (useful for many things) has both a Standby (sleep) and Hibernate command: https://nircmd.nirsoft.net/standby.html Likely does some of the above for you.

user369142
  • 2,575
  • 1
  • 21
  • 9
0

Use

^!Numpad9::DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
^!Numpad8::DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)

in AutoHotkey. You'd then have to press Ctrl+Alt+Numpad9. Ctrl+Alt+Numpad8 is for putting it into hibernation mode.

Aart den Braber
  • 864
  • 1
  • 11
  • 23