本文共 2531 字,大约阅读时间需要 8 分钟。
获取CPU使用率脚本(vbs),另存为cpu.vbs:
On Error Resume NextSet objProc = GetObject("winmgmts:\\.\root\cimv2:win32_processor='cpu0'")Wscript.Echo "CPU 使用率: " & objProc.LoadPercentage & "%"
获取内存使用率脚本(vbs),另存为ram.vbs:
strComputer = "."set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")set colOS = objWMI.InstancesOf("Win32_OperatingSystem")for each objOS in colOSstrReturn = "内存总数: " & round(objOS.TotalVisibleMemorySize / 1024) & " MB" & vbCrLf &"内存可用数: " & round(objOS.FreePhysicalMemory / 1024) & " MB" & vbCrLf &"内存使用率 :" & Round(((objOS.TotalVisibleMemorySize-objOS.FreePhysicalMemory)/objOS.TotalVisibleMemorySize)*100) & "%"Wscript.Echo strReturnnext
获取磁盘使用率脚本(vbs),另存为hard.vbs:
Set fsoobj = CreateObject("Scripting.FileSystemObject") DriversInfo = GetDriversInfo DriversInfo = Replace(DriversInfo, "|", vbCrLf) sReturn ="硬盘信息:" & vbCrLf & DriversInfo Wscript.Echo sReturnFunction GetDriversInfo() GetDriversInfo = "" Set drvObj = fsoobj.Drives For Each D In drvObj Err.Clear If D.DriveLetter <> "A" Then If D.isReady Then GetDriversInfo = GetDriversInfo & "分区:" & D.DriveLetter & vbCrLf GetDriversInfo = GetDriversInfo & "可用空间:" & cSize(D.FreeSpace) & vbCrLf GetDriversInfo = GetDriversInfo & "总大小:" & cSize( D.TotalSize) & vbCrLf GetDriversInfo = GetDriversInfo & "使用率 :" & (100*((D.TotalSize-D.FreeSpace)/D.TotalSize)) &"%" & vbCrLf GetDriversInfo = GetDriversInfo & "|" Else End If Else End If NextEnd Function Function cSize(tSize) If tSize >= 1073741824 Then cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB" ElseIf tSize >= 1048576 Then cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB" ElseIf tSize >= 1024 Then cSize = Int((tSize / 1024) * 1000) / 1000 & " KB" Else cSize = tSize & "B" End IfEnd Function
最后批处理执行以上脚本,另存为“获取CPU、内存和磁盘使用率.bat”
@echo offecho "正在获取CPU、内存和磁盘使用率,请稍候..."echo CPU信息:>info.txtcscript //Nologo cpu.vbs >> info.txtecho.>>info.txtecho 内存信息:>>info.txtcscript //Nologo ram.vbs >> info.txtecho.>>info.txtcscript //Nologo hard.vbs >> info.txt
执行结果如下:
CPU信息:CPU 使用率: 22%内存信息:内存总数: 12132 MB内存可用数: 7354 MB内存使用率 :39%硬盘信息:分区:C可用空间:64.541 GB总大小:102.443 GB使用率 :36.9974772881646%分区:D可用空间:134.282 GB总大小:402.132 GB使用率 :66.6073734064705%分区:E可用空间:47.56 GB总大小:300.003 GB使用率 :84.1468686136043%分区:F可用空间:48.774 GB总大小:220.006 GB使用率 :77.8305072014826%
转自:http://www.fendou.info/vbs-get-cpu-harddisk-ram-rate/
转载地址:http://qjixx.baihongyu.com/