0

Good day, I have a computer running Windows Server 2016. The computer is connected to a UPS via USB where it reads the UPS' remaining charge as if it were its own battery. I need to create a batch file that checks the remaining battery charge, if it's below 60%, then shutdown a remote computer and itself (I can then use the Task Manager for a periodic execution of the batch file). I have found similar questions/answers in the forum but not exactly what I need. Any help with the script would be appreciated :).

EDIT: Thank you for your answer. I can actually get the remaning charge through the Windows Management Instrumentation, so no need to worry about drivers or whatnot. What I want to do is something like the following:

::Get the battery's remaining charge
SET BatteryCharge = WMIC PATH Win32_Battery Get EstimatedChargeRemaining
::Shutdown remote and local computer if charge is less than 60%
IF %BatteryCharge% LSS 60 (
    shutdown -s -m \\remotecomputer -t 10
    shutdown -s -m \\localcomputer -t 10
)

Now I'm not exactly sure how to plug the remaning battery charge to the variable BatteryCharge.

R. Sk
  • 11
  • 3
  • Very likely we'll need information on what kind of UPS, drivers, etc. The information typically isn't just magically available as a serial stream... – roelofs Nov 22 '17 at 02:55
  • 1
    Also, SO is not a codewriting service. If you can show us what you've come up with, we can try and help out. – roelofs Nov 22 '17 at 03:03

1 Answers1

0

you can get the output of a command with a for /f loop:

for /f "tokens=2 delims==" %%a in ('WMIC PATH Win32_Battery Get EstimatedChargeRemaining /value') do set remain=%%a
if %remain% lss 60 echo Battery low
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • If you need more information on how it works then its on this post basically about the same but written another way. https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file – NizonRox Nov 22 '17 at 13:25
  • Much appreciated. – R. Sk Nov 22 '17 at 18:09