Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Need Advice On Script to Automate Windows Standby

by PerlBear (Hermit)
on Aug 30, 2005 at 17:05 UTC ( #487842=perlquestion: print w/ replies, xml ) Need Help??
PerlBear has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Fellow Monks! In a nutshell, I would like to automate placing Windows, in the case Win2000, into standby. The code I have assembled below is for automatic rebooting which works cleanly including a warning window of impending shutdown. I put this in the scheduler for unattended auto rebooting of a remote computer.
#!/usr/bin/perl -w use Win32; Win32::InitiateSystemShutdown( '', "\nWARNING\!\!\n\nSystem is about t +o Reboot\!\n\(The system will reboot in 30 seconds.\)", 30, 1, 1 );
This is what I would call it's "countermeasure" (in case you want to abort a reboot that is about to occur:
#!/usr/bin/perl -w use Win32; $machineName=""; Win32::AbortSystemShutdown($machineName);
I want to create something simliar to the first script shown above except it simply puts the computer in standby or sleep mode. I did a little digging but didn't find anything that was quite obvious right off the bat. Perhaps, maybe this falls into the realm of Windows Scripting, which I am not all that familiar with, but I am willing to adapt; hoping for a perl solution. Any help/insight that can be provided will great!
Thank you in advance for your help and wisdom in this matter!

Comment on Need Advice On Script to Automate Windows Standby
Select or Download Code
Re: Need Advice On Script to Automate Windows Standby
by BrowserUk (Pope) on Aug 30, 2005 at 18:02 UTC

    This may be what you need.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Need Advice On Script to Automate Windows Standby
by PerlBear (Hermit) on Aug 31, 2005 at 12:36 UTC
    Thanks to the great advice, (exactly what I needed), provided by BrowserUk pointing me to a highly relevant section of the MSDN Library regarding SetSuspendState, a Windows power management function; I was able to develop the answer to my own question, to create a script that utilizes the Win32::API to put the Windows computer in a sleep/suspend state. Code below:
    #!/usr/bin/perl -w use strict; use Win32::API; Win32::API->Import( 'PowrProf', 'BOOLEAN SetSuspendState( BOOL Hibernate, BOOL ForceCritical, BOOL DisableWakeEvent )', ); SetSuspendState(0,0,0);
    Thanks Again! Your small bit of highly relevant wisdom has allowed me to come up with the answer to my own question. Precisely what I was looking for!

    Additonal Notes: I have tested this out on Windows 2000 SP4, and it does precisely what I want it to: puts the system in a sleep/suspend state. If you want the system to hibernate, setting the first 0 to 1, (1,0,0), should do the trick (I have not yet tested the hibernate aspect).
    As always, I welcome any constructive suggestions for improvement/enhancement of this code. :)
      Hi Friends, Above code is working perfectly for Standby / Sleep. However, it doesn't make to hibernate, even if we set first parameter to 1 (1,0,0). Could you please anyone provide the hibernation code for windows. Thanks....

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://487842]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-12-26 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls