?
Solved

Batch script to evaulate battery life and take action

Posted on 2014-12-08
3
Medium Priority
?
396 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
[X]
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
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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