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
Microsoft Power State Detect/Respond
Moderators: Dorian (MJT support), JRL
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
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...
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
- CyberCitizen
- Automation Wizard
- Posts: 721
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
Could you disable it at the start of the script & re-enable it once completed?
http://stackoverflow.com/questions/2540 ... mmand-line
http://stackoverflow.com/questions/2540 ... mmand-line
FIREFIGHTER
Thanks for the responses. what a great forum.
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.
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.Phil wrote:You can make an entry into Task Scheduler that re-runs the script
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.CyberCitizen wrote:Could you disable it at the start of the script & re-enable it once completed?
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.Me_again wrote:I'm thinking of something trivial like pinging localhost
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.
- CyberCitizen
- Automation Wizard
- Posts: 721
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
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