Sign in with
Sign up | Sign in
Your question
Solved

Remote shutdown, at shutdown

Last response: in Windows 7
Share
February 23, 2014 9:06:11 PM

I have two computers A and B. Both are running windows 7. Computer A is connecter to a battery backup via usb, computer B is powered by the same backup however is not connected via usb. When AC power is lost computer A is told to shutdown. The battery backup software does not support remote shutdown or running a script/batch file. (APC's Powerchute personal edition). I have a batch file that does what I need but I cannot find a way to run it when computer A is told to shut down. Is this possible?

Best solution

February 24, 2014 6:43:33 AM

You can probably use PowerShell to query the battery status during shutdown. There are WMI classes for the battery. If the battery state is "discharging," you could run the remote shutdown. I'm going to write a sample script for you later today if I get around to it.
Share
February 24, 2014 8:11:36 PM

rusabus said:
You can probably use PowerShell to query the battery status during shutdown. There are WMI classes for the battery. If the battery state is "discharging," you could run the remote shutdown. I'm going to write a sample script for you later today if I get around to it.
Thanks so i would have to run that on computer A so that whent the battery state changes it would then send the shutdown command to computer B correct?


m
0
l
Related resources
Can't find your answer ? Ask !
February 24, 2014 8:26:08 PM

So, I've found 2 different options. I too have an APC UPS powering 2 computers with PowerChute, but I had to uninstall it to get this first solution to work. I also had to uninstall the APC drivers for the battery backup and use the builtin Windows drivers. You could use this as a shutdown script in PowerShell:
  1. if ((Get-WmiObject Win32_Battery).BatteryStatus -eq 1) {Stop-Computer -ComputerName "yourRemoteComputer" -Force}

I'm sure the above could be converted to use WMIC instead of powershell, but I leave that up to you :) 

The second solution is posted on the APC forums, but I didn't test it. http://forums.apc.com/thread/9055

In my case, neither option really works since my switches are not on a battery backup, just my PCs.

Hope that helps.

--Russel

edit

for kicks, I converted the above PowerShell into a batch file that uses WMIC. It should run faster than the PowerShell variant:
  1. @echo off
  2. for /f "usebackq skip=1 eol=" %%i in (`wmic path win32_battery get BatteryStatus`) do (
  3. for /f "tokens=1 delims=:" %%j in ("%%i") do (
  4. if %%j == 1 (
  5. echo Battery is discharging
  6. shutdown /s /m \\computername
  7. )
  8. )
  9. )
m
0
l
February 25, 2014 10:22:12 AM

rusabus said:
So, I've found 2 different options. I too have an APC UPS powering 2 computers with PowerChute, but I had to uninstall it to get this first solution to work. I also had to uninstall the APC drivers for the battery backup and use the builtin Windows drivers. You could use this as a shutdown script in PowerShell:
  1. if ((Get-WmiObject Win32_Battery).BatteryStatus -eq 1) {Stop-Computer -ComputerName "yourRemoteComputer" -Force}

I'm sure the above could be converted to use WMIC instead of powershell, but I leave that up to you :) 

The second solution is posted on the APC forums, but I didn't test it. http://forums.apc.com/thread/9055

In my case, neither option really works since my switches are not on a battery backup, just my PCs.

Hope that helps.

--Russel

edit

for kicks, I converted the above PowerShell into a batch file that uses WMIC. It should run faster than the PowerShell variant:
  1. @echo off
  2. for /f "usebackq skip=1 eol=" %%i in (`wmic path win32_battery get BatteryStatus`) do (
  3. for /f "tokens=1 delims=:" %%j in ("%%i") do (
  4. if %%j == 1 (
  5. echo Battery is discharging
  6. shutdown /s /m \\computername
  7. )
  8. )
  9. )


Awesome thank you, I will have to try these out when i get off work.
m
0
l
!