vbs CPU 内存 硬盘监控脚本
On Error Resume Next Dim dwTotalMem, dwAvailMem, totalvolumn, freespace Const szRootDir = "D:CPU" Set oFSO = CreateObject("Scripting.FileSystemObject") Const ForReading = 1 Const ForWriting = 2 '计算当日记录文件名 Today = Date() TargetFile = szRootDir & Year(Today) & Right("00" & Month(Today),2) & Right("00" & Day(Today),2) & Hour(Now) & ".log" '没有文件先创建文件 Set MyFile = oFSO.CreateTextFile(TargetFile, false) MyFile.Close Set MyFile = oFSO.OpenTextFile(TargetFile, ForWriting) '写开始时间 MyFile.WriteLine("程序启动时间: " & Now()) '本地电脑 strComputer = "." '连接到本地电脑 Set objWMIService = GetObject("winmgmts:\" & strComputer & " ootcimv2") Set colItems = objWMIService.InstancesOf("Win32_OperatingSystem") '总计物理内存 For Each colItem In colItems dwTotalMem = colItem.TotalVisibleMemorySize dwTotalMem=round(dwTotalMem/1024,2) MyFile.WriteLine("总计物理内存: " & dwTotalMem & "MB") Next MyFile.WriteLine("") '剩余内存 Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfOS_Memory",,48) For Each objItem in colItems dwAvailMem = objItem.AvailableMBytes MyFile.WriteLine("剩余物理内存: " & objItem.AvailableMBytes & "MB") Next MyFile.WriteLine("") 'CPU数和使用率 Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48) i = 0 j = 0 For Each objItem in colItems j = j + objItem.LoadPercentage i = i + 1 Next j = j/i j = round(j,2) MyFile.WriteLine("CPU使用率: " & j & "%") MyFile.WriteLine("") Set colDrives = oFSO.Drives For Each objDrive in colDrives If objDrive.IsReady = True Then MyFile.WriteLine("盘符: " & objDrive.DriveLetter&" "&"磁盘名称: " & objDrive.VolumeName) MyFile.WriteLine("") totalvolumn = objDrive.TotalSize freespace = objDrive.FreeSpace totalvolumn = round(totalvolumn/1024/1024/1024,2) freespace = round(freespace/1024/1024/1024,2) MyFile.WriteLine("总容量:" & totalvolumn & "GB" & " " & "剩余容量: " & freespace & "GB") MyFile.WriteLine("") End If Next MyFile.Close Set oFSO = Nothing Set MyFile = Nothing
vbs 磁盘监控详细
Set objFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = objFSO.Drives For Each objDrive in colDrives If objDrive.IsReady = True Then Wscript.Echo "盘符: " & objDrive.DriveLetter wscript.echo "磁盘序列号:" & objDrive.SerialNumber wscript.echo "磁盘类型:" & objDrive.DriveType wscript.echo "文件系统的类型:" & objDrive.filesystem wscript.echo "磁盘名称: " & objDrive.VolumeName wscript.echo "总容量:" &objDrive.TotalSize Wscript.Echo "剩余容量: " & objDrive.FreeSpace wscript.echo "可选容量:" & objDrive.AvailableSpace Else Wscript.Echo "盘符: " & objDrive.DriveLetter End If Next