Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Batch script to evaulate battery life and take action

Posted on 2014-12-08
3
331 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 84

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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