|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这个虽然效率低了点,凑合也能用(上面代码手打了一行,或许电脑原因,获取失败)^_^:
- Sub 查询CPU()
- Dim WmiObj As Object
- For Each WmiObj In GetObject("Winmgmts:").InstancesOf("Win32_Processor")
- MsgBox "当前CPU使用率为:" & WmiObj.LoadPercentage & "%"
- Next
- End Sub
- Sub test()
- Dim sComputerName, WMI_Obj, WMI_ObjProps, ObjClsItem
- sComputerName = Environ("computername")
- If Len(Trim(sComputerName)) = 0 Then sComputerName = "."
- Set WMI_Obj = GetObject("winmgmts:\" & sComputerName & "\root\cimv2")
- Set WMI_ObjProps = WMI_Obj.ExecQuery("Select * from Win32_Processor", , 48)
- For Each ObjClsItem In WMI_ObjProps
- MsgBox "AddressWidth: " & ObjClsItem.AddressWidth
- MsgBox "Architecture: " & ObjClsItem.Architecture
- MsgBox "Availability: " & ObjClsItem.Availability
- MsgBox "Caption: " & ObjClsItem.Caption
- MsgBox "ConfigManagerErrorCode: " & ObjClsItem.ConfigManagerErrorCode
- MsgBox "ConfigManagerUserConfig: " & ObjClsItem.ConfigManagerUserConfig
- MsgBox "CpuStatus: " & ObjClsItem.CpuStatus
- MsgBox "CreationClassName: " & ObjClsItem.CreationClassName
- MsgBox "CurrentClockSpeed: " & ObjClsItem.CurrentClockSpeed
- MsgBox "CurrentVoltage: " & ObjClsItem.CurrentVoltage
- MsgBox "DataWidth: " & ObjClsItem.DataWidth
- MsgBox "Description: " & ObjClsItem.Description
- MsgBox "DeviceID: " & ObjClsItem.DeviceID
- MsgBox "ErrorCleared: " & ObjClsItem.ErrorCleared
- MsgBox "ErrorDescription: " & ObjClsItem.ErrorDescription
- MsgBox "ExtClock: " & ObjClsItem.ExtClock
- MsgBox "Family: " & ObjClsItem.Family
- MsgBox "InstallDate: " & ObjClsItem.InstallDate
- MsgBox "L2CacheSize: " & ObjClsItem.L2CacheSize
- MsgBox "L2CacheSpeed: " & ObjClsItem.L2CacheSpeed
- MsgBox "L3CacheSize: " & ObjClsItem.L3CacheSize
- MsgBox "L3CacheSpeed: " & ObjClsItem.L3CacheSpeed
- MsgBox "LastErrorCode: " & ObjClsItem.LastErrorCode
- MsgBox "Level: " & ObjClsItem.Level
- MsgBox "LoadPercentage: " & ObjClsItem.LoadPercentage
- MsgBox "Manufacturer: " & ObjClsItem.Manufacturer
- MsgBox "MaxClockSpeed: " & ObjClsItem.MaxClockSpeed
- MsgBox "Name: " & ObjClsItem.Name
- MsgBox "NumberOfCores: " & ObjClsItem.NumberOfCores
- Next
- End Sub
复制代码 |
|