在VBScript中进行修改

时间:2019-05-06 13:19:34

标签: vbscript

我正在尝试根据自己的喜好获取电池警报。 但是,已经在网上研究中找到了此代码。

Set oLocator = CreateObject("WbemScripting.SWbemLocator")
Set oServices = oLocator.ConnectServer(".","root\wmi")
Set oResults = oServices.ExecQuery("select * from batteryfullchargedcapacity")
For Each oResult In oResults
    iFull = oResult.FullChargedCapacity
Next

While (1)
    Set oResults = oServices.ExecQuery("select * from batterystatus")
    For Each oResult In oResults
        iRemaining = oResult.RemainingCapacity
        bCharging = oResult.Charging
    Next
    iPercent = ((iRemaining / iFull) * 100) Mod 100
    If bCharging And (iPercent > 98) Then MsgBox "Battery is almost full " & iPercent & "%" & " Please disconnect your charger immediately to avoid over charging." & " Over charging the battery may cause damage to your laptop.", vbInformation, "Battery Monitor"
    WScript.Sleep 8000 ' 2 minutes
Wend

当电池以98%的电量充电时,我想在弹出框的同时发出声音警报,即使单击屏幕上的任何位置,也不应将其放在前台。 结束脚本的唯一方法应该是断开笔记本电脑充电器的连接。

0 个答案:

没有答案