运行后会每十分钟记录一次电池电量,记录存储位置在程序目录下的Report目录格式为.csv,可使用Office打开后自助生成电池使用曲线。
若需要修改记录间隔时间请替换代码第20行(单位:ms)。
Battery.vbs
On Error Resume Next
Dim fso,WshShell,colItems,FileName,Folder
Dim objItem 'as Win32_Battery
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set WshShell = WScript.CreateObject("Wscript.Shell")
Folder = WshShell.CurrentDirectory& "\Report"
' 判断文件夹是否存在
If fso.folderExists(Folder) <> True Then
fso.CreateFolder(Folder)
End If
Do ' 操作文件
FileName = WshShell.CurrentDirectory + "\Report\" + replace(date,"/", "-") + ".csv"
Set File = fso.OpenTextFile(FileName, 8, True)
Set colItems = GetObject("winmgmts:\\" & "." & "\root\cimv2").ExecQuery("Select EstimatedChargeRemaining from Win32_Battery",,48)
For Each objItem in colItems
File.WriteLine (Left(Time,5) & chr(44) & objItem.EstimatedChargeRemaining) & chr(37)
Next
WScript.Sleep 600000
Loop