Jump to content

Is there any way to enter standby mode from a batch file?


CamTron

Recommended Posts

I know that you can use "rundll.exe user.exe,exitwindows" to shut down the computer, "rundll.exe user.exe,exitwindowsexec" to reboot, etc., but I haven't found a way to make the computer enter standby (or sleep mode as it's called in Vista and later) through a batch file. My previous keyboard had a button for this, but since that one died on me, my new keyboard lacks a standby button, and I find it a bit inconvenient to open the start menu, click Shut Down and select Stand by from the drop down menu.

Link to comment
Share on other sites


Perhaps i can suggest you this simple "hardware" solution: set the power button of your pc as a standby button.

These are the steps: press right-click on your desktop, then properties -> screen saver -> power -> advanced. Therefore select Standby in "When i press the power button on my computer".

Link to comment
Share on other sites

Rundll32.exe Kernel32.dll,SetSystemPowerState
This works in a shortcut to which you can assign a hot key and icon of your choice.

To be fully compatible with Rundll/Rundll32, a 16/32-bit function must have four parameters like WinMain. SetSystemPowerState has only three parameters so after the system comes out of suspend you will see a system error dialog.

WSH scripts can surely be written to simulate pressing the Suspend key, or even to call SetSystemPowerState directly. The code could be written to a temp file by a batch file if you really need batch support. Ask in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.) and someone will probably rise to the challenge.

Link to comment
Share on other sites

I just wrote this really simple C++ program, assigned a keyboard shortcut to it, and it does the trick!

#include <windows.h>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){    if(!SetSystemPowerState(TRUE, FALSE))    {        MessageBox(NULL, "Could not enter standby mode.", NULL, MB_ICONERROR | MB_OK);        return 1;    }    return 0;}
Link to comment
Share on other sites

And even simpler:

void WinMainCRTStartup (void) {  SetSystemPowerState (!!GetModuleHandle("Suspend.exe\0.................."), TRUE);  ExitProcess (0);}
Suspends to RAM (forced) if named Suspend.exe. To hiberate/suspend-to-disk instead, change the filename.

Extra space reserved for hexing of filename string needed for Suspending to RAM.

Suspend.7z

Edited by jumper
Link to comment
Share on other sites

Has anyone tested SetSuspendState() in powrprof.dll?

I have a Win2000 version of the library on my main 98SE system. Unfortunately no guinea pig-machine to test on, at the moment.

 

There are a few other useful APIs such as IsPwrHibernateAllowed(), IsPwrSuspendAllowed(), IsPwrShutdownAllowed() that could report whether a certain state can be induced or not, as well as the more complex GetPwrCapabilities() that returns a structure full of power-related information.

 

I assume IsPwrHibernateAllowed() and IsPwrSuspendAllowed() would eliminate the frustration of not being able to set a certain power state.

Link to comment
Share on other sites

Has anyone tested SetSuspendState() in powrprof.dll?

I have a Win2000 version of the library on my main 98SE system. Unfortunately no guinea pig-machine to test on, at the moment.

 

There are a few other useful APIs such as IsPwrHibernateAllowed(), IsPwrSuspendAllowed(), IsPwrShutdownAllowed() that could report whether a certain state can be induced or not, as well as the more complex GetPwrCapabilities() that returns a structure full of power-related information.

 

I assume IsPwrHibernateAllowed() and IsPwrSuspendAllowed() would eliminate the frustration of not being able to set a certain power state.

I could test it, what version is it?
Link to comment
Share on other sites

Well this is a very interesting question.

ProductVersion says 5.00.0910.1900 and ProductName says 'Microsoft® Windows ® 2000 Operating System'.

However, the file timestamp is 1999.04.23, which means it's the original file that shipped with 98SE. And indeed, checking with the CD it is the original file.

I now wonder, how come an official 98SE file delivered in '99 appears as belonging to Windows 2000…

 

Anyway, I've already performed some limited tests and all above-mentioned APIs except for SetSuspendState() do work correctly. I haven't tried the latter because I don't like my hard drive to be stopped unnecessarily.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...