【问题标题】:How can I set the output value of a WMIC command to check the notebook battery as a batch variable?如何设置 WMIC 命令的输出值以将笔记本电池检查为批处理变量?
【发布时间】:2022-08-06 18:17:19
【问题描述】:

我想读出有关电池的详细信息,如下所示:

WMIC PATH Win32_Battery Get EstimatedChargeRemaining

例如,我可以使用%value% 变量显示此输出吗?

    标签: batch-file wmic


    【解决方案1】:

    此任务的批处理文件是:

    @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 class 的 Microsoft 文档页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 2017-04-20
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多