3 Ways to Use One UPS on Multiple Computers
Most computer users would know that properly shutting down a desktop PC is very important to prevent your files from getting corrupted and it also minimizes the risk of damaging the hard drive. However, there are times when things are just out of your control such as an unexpected power failure or your kid pulling the plug out of the socket which causes a forced shut down. One way to keep your computer running when there is no electricity, giving you enough time to properly shut down your computer, is by using a battery backup known as Uninterruptible Power Supply (UPS).
A more affordable lower range home based UPS normally has a few battery protected and surge-only outlets but with only 1 USB connection. The USB is for the UPS to tell the computer how much power is left on the battery so you can then either use the UPS manufacturer’s software or from the Windows power options perform a graceful shutdown before the battery is depleted. This would mean only 1 computer can know when the battery level is low and auto shutdown the computer but the rest of the computers connected to the other remaining battery protected outlets won’t know and cannot be configured to automatically shutdown.
In this article we’ll show you a couple of ways on how you can use one UPS on multiple computers and automatically shut down all the computers that are connected to that one single UPS.
The technique used in this workaround is actually pretty simple. All you need to do is get the computer that is connected to the UPS via USB connection to send out commands which can remotely shut down other computers when the battery has reached a low or critical level. So the only requirement here is the computers must be connected via local area network either by wireless or cable.In Windows XP, this can be easily achieved because the operating system allows you to run a custom program when the battery power level is low. However starting from Windows Vista until the current Windows 8.1, this useful option has been limited to only allow you to choose either two actions which is sleep or shut down.
Run custom program or script when power is low in Windows 7
1. Shutter
Shutter is a very straight forward scheduling utility that allows you to perform certain actions based on a selection of events. There is a “Battery Low” event which you can set it to trigger an event when the battery level drops below specific level.
To run a custom batch file or program when the battery reaches a low level using Shutter, you’ll first need to add an event by clicking on the Add button on the event, select Battery Low, optionally change the percentage of the battery level and click Add. Now click the Add button from the Action, select Open File and choose the batch file that you want to run. Click Add and finally the Start button.
Whenever your battery level reaches 5%, Shutter will simply run the custom batch file. It would make sense to automatically run Shutter on Windows startup which can be done from the General tab in Options. You will need to select “Autorun at Windows startup/logon” (all users or current users) and optionally “minimize on start of event monitoring”. Most importantly, go to Advanced tab and select “Start event monitoring when application launches” or else the program only starts up but don’t monitor the event.
The Lite version is free for non commercial use but is limited to number of events and actions with a nag popup on program startup. Shutter takes up merely a few megabytes of memory and nearly zero CPU usage. A portable version is available to download.
2. BatteryDeley
BatteryDeley is another small program created with AutoHotkey that can be configured to run custom programs when a battery has reached a certain level. It is not that user friendly like Shutter because it doesn’t have a graphical user interface and the configuration is done by manually editing the BatteryDeley.ini file. By default, BatteryDeley merely plays a sound and display a small popup image when reaching a certain battery level and when external power is unplugged or plugged back in.
Configuring BatteryDeley to run a custom program when reaching a certain battery level is actually quite easy if you’re familiar with paths in Windows. Open BatteryDeley.ini with your favorite text editor such as Notepad or Notepad++. The top part of the configuration file that starts with semicolon are examples and explanations of what each line does.
Basically you’ll only need to edit the alertXpct and alertXcmd values where the pct is the percentage of the battery level and the cmd is the path of the custom program that you want to run. The screenshot below shows that when the battery level reaches 5%, a shutdown.bat file will be ran.
BatteryDelay doesn’t have a built-in option to auto start with Windows so you’ll need to create a shortcut of BatteryDeley.exe and drop it in your Startup folder.
3. Task Scheduler
This method doesn’t involve using any third party software but it is kind of a hackish way of accomplishing it directly from Windows. The trick here is to enable away mode which actually takes over the sleep mode and use the Task Scheduler to run a program when it detects a triggering event (Sleep Mode). The reason why we can’t use Sleep Mode is because it doesn’t create an event but Away Mode does.
To enable Away Mode, simply download (AwayModeEnabled.reg) and run the registry file which we’ve created for your convenience. Once you’ve imported the AwayModeEnabled.reg file to your registry, whenever your computer goes to Sleep, it will enter Away Mode instead.
Now run Task Scheduler by simultaneously pressing WIN + R keys and type taskschd.msc followed by hitting the Enter key. Click on Create Task at the right actions pane and a Create Task window will open. Give it a name for this task (e.g. Run program on Low Battery). Go to Triggers tab and click the New button. Enter the information as shown below.
- Begin the task: On an event
- Settings: Basic
- Log: System
- Source: Kernel-Power
- EventID: 59
- Enabled Checkbox: Ticked
Now to go Actions tab and click on the New button. For the action drop down menu, select Start a program which should be chosen by default and click the Browse button to select the batch file or program that you want to run when battery power level is low.
Go to Conditions tab, uncheck “Start the task only if the computer is on AC power” and click OK.
Go to Control Panel > Hardware and Sound > Power Options. Click on the “Change plan settings” for the selected preferred plan and click “Change advanced power settings”. Expand Battery > Critical battery action OR Low battery action and select Sleep for On battery on either options. By default Low Battery Action is at 10% while Critical is at 5%. Both of these values can be changed in the Power Options Advanced Settings.
Sending Remote Shutdown Commands when Battery is Low
Now that you are able to run a custom script or program when the battery level is low on the newer Windows operating system, you’ll just need to write a batch file / script that can remotely turn off multiple computers that are connected to the other battery protected outlets. You can rely on third party software such as DShutdown, PowerOff, psshutdown/psexec that supports command line options to do that.
If using DShutdown:
DShutdown.exe /NOW /IP:192.168.1.1 /poweroff /IP:192.168.1.2 /poweroff /IP:192.168.1.3 /poweroff
DShutdown.exe /NOW /poweroff
If using PowerOff:
poweroff.exe poweroff -force -remote 192.168.1.1 -port 3210 -password MyPASS
poweroff.exe poweroff -force -remote 192.168.1.2 -port 3210 -password MyPASS
poweroff.exe poweroff -force -remote 192.168.1.3 -port 3210 -password MyPASS
poweroff.exe poweroff
If using psshutdown.exe:
psshutdown.exe -r -f -u yourusername -p yourpassword \\192.168.1.1
psshutdown.exe -r -f -u yourusername -p yourpassword \\192.168.1.2
psshutdown.exe -r -f -u yourusername -p yourpassword \\192.168.1.3
shutdown -s -f -t 0
If using psexec.exe:
psexec.exe \\192.168.1.1 -u yourusername -p yourpassword shutdown /s /f
psexec.exe \\192.168.1.2 -u yourusername -p yourpassword shutdown /s /f
psexec.exe \\192.168.1.3 -u yourusername -p yourpassword shutdown /s /f
shutdown -s -f -t 0
You’ll only need to copy either one of the set of commands above to the shutdown.bat file depending on which program you prefer using perform the remote shutdown. The first three lines are to shutdown computer from IP address 192.168.1.1 to 192.168.1.3 (you’ll need to replace the IP addresses with the ones used on your computer) and the last line is to shutdown the local computer.
Additional Note: You might want to increase the low battery level to 20% from the Power Options Advanced Settings so that there will be enough time for all the computers to properly shut down before the battery power runs out.
Important Note: You need to make sure that the total output power capacity of all the computers connected to the battery protected outlets are not over the UPS output power capacity. Overloading the output power capacity can potentially damage the UPS and your computers. As long as the overload warning light does not turn on, then it should be safe.
You just should take care that your switch is also connected to the UPS, otherwise the remote shutdown might be useless.
mmmm…Or use a 5 dollars powered USB HUB (powered of course by the UPS otherwise in case of blackout it will not work…) and connect it to the only USB port of your UPS.
WOW…now you have multiple USB ports…
Now connect how many computers you want to the HUB USB….
No need of scripting or wizardries or UPS network cards or SNMP traps.
DUH…
so an adapter to usb type A, to a 4 way USB unpowered hub and plug (in my case – two nas servers) into the hub and pray?
this does not work.. I bout a powered USB HUM and a passive USB HUB, Neither of them worked.
With the passive one, though, When I connected the passive hub TO a computed and the UPS to one of the client, only then did the the signal reach the computer.
Long story short, Hub didnt work in the (path) way I needed it to.
Agreed, this set works. I have an APC UPS unit with an unpowered USB Hub on it. And my two NASs connect to this Hub. , Sure enough upon a power loss the two NASs get a signal from the UPS to shut down safely.
I created an open source program that is similar to batterydeley. It can execute a powershell, exe, or batch file. To any who find it useful, here’s the link. sourceforge.net/projects/battery-script-executor/
Feel free to modify or redistribute the code non-commercially.
Thanks for this, after spending some time looking for a decent solution I came across this and got the script setup on my ESXi host/Windows VM using the Task Scheduler solution. I just ran a test and everything gracefully shutdown. Upon power restoration, it all came back up.
For those curious on specific setup for ESXI that I used… In vSphere, Host->Configuration Tab->Virtual Machine Startup/Shutdown->Properties and set Shutdown Action to Guest Shutdown. Pass the UPS through to a VM, Setup a script on that VM I called it esxidown.sh with “/sbin/shutdown.sh && /sbin/poweroff” as its contents.
This will gracefully shutdown the guests before proceeding to shutdown the Host but sends both commands at once so that it doesn’t have to get a command from an already-shutdown VM after it completes VM shutdowns.
Now make a .bat for PuTTy/plink with ‘ “path\to\plink.exe” -ssh -l root -pw youresxirootpassword -P 22 -m “path\to\shutdownscript.sh” Your.ESXi.Host.IP ‘ (this could probably be done more securely with ssh keys, but I’m not sure and don’t need it in my application)
Now use the directions above to use Task Scheduler to call the .bat you just made.
Auto-up on power restoration obviously depends upon the Host’s BIOS capabilities and settings, but I think most relatively modern machines support it.
Thanks again and hope this helps someone else in my situation.
These work great for laptops, or for UPS appliances that report themselves to the OS as an internal battery. However, for those external appliances that do not, using Task Scheduler (option #3) is required, and the trigger must be changed.
For instance, APC logs an entry into the Application log when it converts to battery power. That log entry can be used as the trigger instead of the one listed in this article. (For other models, you can get the parameters required for the Task Scheduler entry by unplugging your UPS, then examining the log files to locate the one generated by your UPS.)
Hi Ray,
Great article;
Thanks.
Can you let me know which UPS has the USB port to tell the computer ….i mean the UPS model which allows to gracefully shutdown computer without user intervention?
-tinornit
APC ups has usb and graceful shutdown capability, some models not all, check its website. On a side note, i did not install powerchute but use windows 7 default options, just like in a laptop.
Thank you Boss !!! It’s Really helpful !!!
well and nice
I also just used that program to create a batch file to turn off my monitors for my MCE2005 box. I put a shortcut to it in the “more programs” list so I can navigate to that to shut my monitors off if I’m laying down while watching TV through MCE.
The batch file consists only of this:
poweroff monitor_off
There was another workaround for MCE using a different style program. This one is much better since it doesn’t minimize MCE while shutting off the monitors.
Thank you for this article! I was looking for a way to have my main PC and Windows Home Server box protected with one UPS.
Poweroff installs and runs fine on WHS; thank you again!
Nice blog.. and nice idea..!
thanks
Thanks Ray!