Link to home
Start Free TrialLog in
Avatar of speeDemon
speeDemonFlag for United States of America

asked on

PC to send shutdown command to all Windows PC's in room when it detects loss of utility power and is on battery backup power

I have a training room, One BIG UPS (APC) that powers all the trianing PC's. I need the PC that has the one data signal (to know when it is on battery backup power) to send a shutdown signal to the other PC's that are on the battery power, but cant know because of the single datacable.

Any ideas?
Avatar of Gary Dewrell
Gary Dewrell
Flag of United States of America image

If you are using powerchute then you can have it execute a script that will remotely issue shutdown commands to your other PC's. You could use Powershell or PSExec or even use Task Scheduler to schedule a remote task to run in x minutes that issues the shutdown command.
Avatar of ktaczala
If someone is handling the Main PC and comes to know that its running on Battery Backup Power, he can run a script or batch file or use psexec command to shutdown all other PC which are on network. To execute this command you must have to run the Batch with User account which has got Admin access on all the PC. If all those are in Domain then would be much easier.

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

Not sure if there is any way to detect system has switched from Online Power to Battery Power, through any script which can be scheduled to run every 5 minutes to do the monitoring of the Status.
Avatar of skullnobrains
skullnobrains

you can use the windows events to detect the power change
here is a software that does this and launches actions on power change
http://batterysaver.codeplex.com/

you can use it to run a psshutdown command
speeDemon, did you get your answer or are you still looking for advice?
I do this currently but I won't get into the details if you've already been helped...and there are plenty good suggestions above.
Avatar of speeDemon

ASKER

i have not found a solution yet, no. I am going to try the powersaver codeplex option soon
after a little browsing, i found this vbscript which queries the battery status. sorry, i cannot post the URL : i stupidly lost the page where i found it

it should be fairly easy to modify it to spawn an external psshutdows command or even to script the shutdown of the other computers based on this

strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi")
 
Set colItems = objWMIService.ExecQuery("Select * From BatteryStatus Where Voltage > 0")
 
For Each objItem in colItems
    Wscript.Echo "Battery: " & objItem.InstanceName
    Wscript.Echo "On AC Power: " & objItem.PowerOnline
    Wscript.Echo "Battery is Discharging: " & objItem.Discharging
    Wscript.Echo "Battery is Charging: " & objItem.Charging
    Wscript.Echo "Remaining capacity: " & objItem.RemainingCapacity
Next

Open in new window


you'd need to run it on a regular basis as a job

whatever solution you use, you'd better be careful not to stop all your machines if the AC power gets down for a milisecond

please don't forget to post back because i believe this issue is interesting to many other people (myself included)
I'll tell you what I use, it works very well for me.

I use "winapcupsd" instead of "Powerchute" to monitor my UPS from the PC it's connected to, You can download and install from here:

http://sourceforge.net/projects/apcupsd/files/win-binaries%20-%20Stable/3.14.10/

You should use "psshutdown" or "psexec" to initiate remote shutdown from your UPS connected PC to your other machines. Download the suite of tools from here:

http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

Depending on the remote machine's OS, you may have more success with "psshutdown" vs. "psexec". My script has a sample shutdown command using both methods. Use whichever works best for you.

APCUPSD allows you to run scripts when it detects a power outage (and all other power events too). So what you do is write a script (I attached examples) that remotely sends a shutdown to your other machines during a power outage.  You can also write a script (sample included) to cancel the shutdown process if the power is restored.

See my attached 2 sample text files. I renamed them .txt just to submit here but they are really .bat files. Rename them to .bat for use. You could use my 2 files, but just insert your own machine names and credentials.

My scripts below send a shutdown command to my remote machines, telling them to shut down in 5 minutes (300 seconds).

At the top of the scripts, it says where to place these 2 batch files inside of the \apcupsd\ folder structure.

Let me know if you have questions, problems.
onbattery.txt
offbattery.txt
ZabagaR, this looks like it will work. Can i get a copy of your configuration file? I can not see the location to specify where to call the script by name on power fail and power resume.

Thank you
ASKER CERTIFIED SOLUTION
Avatar of ZabagaR
ZabagaR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great work ZabagaR. My inital testing was a success. Thanks for the help.