您好,我有一台运行Windows Server 2016的计算机。计算机通过USB连接到UPS,在那里它读取UPS的剩余电量,就像它是自己的电池一样。我需要创建一个批处理文件来检查剩余电池电量,如果电池电量低于60%,则关闭一台远程计算机及其本身(然后我可以使用任务管理器定期执行批处理文件)。我在论坛上找到了类似的问题/答案,但并不完全是我需要的。对脚本的任何帮助都将不胜感激:)。
编辑:感谢您的回答。实际上,我可以通过Windows Management Instrumentation获得剩余费用,因此无需担心驱动程序或诸如此类的问题。我想做的事情如下所示:
::Get the battery's remaining charge
SET BatteryCharge = WMIC PATH Win32_Battery Get EstimatedChargeRemaining
::Shutdown remote and local computer if charge is less than 60%
IF %BatteryCharge% LSS 60 (
shutdown -s -m \\remotecomputer -t 10
shutdown -s -m \\localcomputer -t 10
)现在我不确定如何将剩余的电池电量插入到变量BatteryCharge中。
发布于 2017-11-22 20:42:00
您可以使用for /f循环获取命令的输出:
for /f "tokens=2 delims==" %%a in ('WMIC PATH Win32_Battery Get EstimatedChargeRemaining /value') do set remain=%%a
if %remain% lss 60 echo Battery lowhttps://stackoverflow.com/questions/47426041
复制相似问题