Solved

Batch script to evaulate battery life and take action

Posted on 2014-12-08
3
298 Views
Last Modified: 2014-12-09
I'm having trouble getting this script to work. My plan is to take one course of action if battery life is less than 50% and take another action for battery life is 50% or higher.

set CRITICALLEVEL=50
for /f "skip=1" %%a in ('wmic path Win32_Battery get EstimatedChargeRemaining') do if %%a gtr 0 set BATTERYLEVEL=%%a
if %BATTERYLEVEL% leq %CRITICALLEVEL% goto CRITICAL if %BATTERYLEVEL% gtr %NOPOWERLEVEL% goto UPDATEFIRMWARE


:UPDATEFIRMWARE
Echo Firmware about to install
Echo Battery life is at %BATTERYLEVEL%
goto eof

:CRITICAL
Echo Battery is too low to update
Echo Battery life is at %BATTERYLEVEL%

:EOF
Echo Done

Open in new window


Any help here would be great.
0
Comment
Question by:hpops
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40488252
Something like this?
@echo off
setlocal
set CriticalLevel=50
set BatteryLevel=-1
for /f %%a in ('wmic.exe path Win32_Battery get EstimatedChargeRemaining ^| findstr.exe /r "[0-9][0-9]*"') do set BatteryLevel=%%a
if "%BatteryLevel%"=="-1" (
	echo No battery found; keep the machine plugged in.
	goto UpdateFirmware
)
echo Battery level is at %BatteryLevel%%%.
if %BatteryLevel% leq %CriticalLevel% (
	echo Battery level is less than %CriticalLevel%, so too low to update.
	pause
	goto :eof
)
:UpdateFirmware
echo Firmware is about to install ...

Open in new window

0
 

Author Comment

by:hpops
ID: 40488659
oBdA,

You nailed it. This works perfectly.

Thanks for your effort.
Dave
0
 

Author Closing Comment

by:hpops
ID: 40488662
Great job on answering this question. Thanks again!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now