Microsoft Power State Detect/Respond

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Microsoft Power State Detect/Respond

Post by JRL » Thu May 23, 2013 5:14 pm

Would it be possible to have a new function(s) that could give scripts the ability to receive and respond to Microsoft power messages?

For example: Imagine I have a script that is humming along sitting in a loop waiting for a user response. The user has gone to lunch but their computer is configured to go into sleep mode after 20 minutes of inactivity. I don't want to move the mouse at intervals to prevent sleep mode as that will also prevent their screen saver from activating but I do want to prevent sleep mode because it causes problems with the script. If the script could register for the Microsoft power messages then respond to such a message with "DENY", the unwanted sleep mode could be thwarted.

Maybe there is another way. Anyone have any ideas?

Thanks
Dick

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu May 23, 2013 10:21 pm

You can make an entry into Task Scheduler that re-runs the script (or another task) with a Trigger of:

Log: System
Source: Power-Troubleshooter
Event ID: 1

I know this is not really what you wanted but it may help a bit. I believe you can add that on install of a script too.

For example: I have a script that checks a web page (for an update) on every boot. But if the system is hibernated or Slept it doesn't work, so I added it to the Task Scheduler as above.

As often the case - This may be a very long winded way of doing something much simpler though...
Phil Pendlebury - Linktree

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri May 24, 2013 5:51 am

Could you disable it at the start of the script & re-enable it once completed?

http://stackoverflow.com/questions/2540 ... mmand-line
FIREFIGHTER

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri May 24, 2013 11:26 pm

To keep it as universal as possible I would look for some benign way of generating "activity" besides moving the cursor, I'm thinking of something trivial like pinging localhost.

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat May 25, 2013 4:55 am

Thanks for the responses. what a great forum.
Phil wrote:You can make an entry into Task Scheduler that re-runs the script
Thanks for the idea, I can see how this could be useful in many cases but it isn't going to work for this particular script. I can't have the script running while in sleep or hibernation and the compiled script is initiated by the user rather than being scheduled.
CyberCitizen wrote:Could you disable it at the start of the script & re-enable it once completed?
Possibly, I'll look into that to see if it will work. Won't be back at work until Tuesday though so its going to be a few days before I can try this.
Me_again wrote:I'm thinking of something trivial like pinging localhost
Have you tried this? does it work? I guess its easy enough to test, I'll see if that works. the problem with the "stackoverflow" command line method is that I'd still need to figure out a way to determine if power saving is turned on. I don't want to turn it on in computers that didn't previously have it set.

Another possible solution/tact for me would be to simply have a way to kill the script if sleep or hibernation is initiated. Funny how "simply" slipped in there so easily considering I don't know how to do that either.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon May 27, 2013 6:44 am

The power detection function is definitely a wonderful idea.
When System Idle Process declines below 50%, most MS macros will run slowly and, even worse, all PRESS keys wil be missing by Windows.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon May 27, 2013 8:03 am

You could try sending this, however I would export the existing power plan / settings first so they can be imported once completed.

Code: Select all

Setting a value to never can be done by passing a value of 0 to the -change option, i.e.:

powercfg.exe -change -monitor-timeout-ac 0

means the monitor timeout will be set to "Never". So the presentation plan can be achieved via:

powercfg.exe -change -monitor-timeout-ac 0
powercfg.exe -change -disk-timeout-ac 0
powercfg.exe -change -standby-timeout-ac 0
powercfg.exe -change -hibernate-timeout-ac 0
FIREFIGHTER

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon May 27, 2013 8:24 am

CyberCitizen,
Thanks for your feedback.
I still prefer the suggested power defection feature function to vary my wait time settings dynamically:
WW_TIMEOUT
WSI_TIMEOUT
WST_TIMEOUT

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts