簡體   English   中英

如何設置 WMIC 命令的輸出值以將筆記本電池檢查為批處理變量?

[英]How can I set the output value of a WMIC command to check the notebook battery as a batch variable?

我想讀出有關電池的詳細信息,如下所示:

WMIC PATH Win32_Battery Get EstimatedChargeRemaining

例如,我可以使用%value%變量顯示此輸出嗎?

此任務的批處理文件是:

@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

要了解所使用的命令及其工作原理,請打開命令提示符窗口,在其中執行以下命令,並仔細閱讀每個命令顯示的所有幫助頁面。

  • echo /?
  • endlocal /?
  • for /?
  • if /?
  • set /?
  • setlocal /?
  • wmic /?
  • wmic path /?
  • wmic path win32_battery /?
  • wmic path win32_battery get /?

另請參閱Win32_Battery 類的 Microsoft 文檔頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM