'How can I set the output value of a WMIC command to check the notebook battery as a batch variable?
I want to read out details about the battery as follows:
WMIC PATH Win32_Battery Get EstimatedChargeRemaining
Can I then display the output of this using the %value% variable, for example?
Solution 1:[1]
The batch file for this task is:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "EstimatedChargeRemaining="
for /F "tokens=2 delims==" %%I in ('%SystemRoot%\System32\wbem\wmic.exe PATH Win32_Battery GET EstimatedChargeRemaining /VALUE 2^>nul') do set "EstimatedChargeRemaining=%%I"
if defined EstimatedChargeRemaining echo Estimated remaining battery charge: %EstimatedChargeRemaining% %%
endlocal
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?endlocal /?for /?if /?set /?setlocal /?wmic /?wmic path /?wmic path win32_battery /?wmic path win32_battery get /?
See also the Microsoft documentation page for the Win32_Battery class.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mofi |
