求解,用VB获取系统信息问题
Private Sub Command1_Click()
Dim TEXzh()
n = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor", , 48)
For Each objItem In colItems
ReDim Preserve TEXzh(n)
TEXzh(n) = " CPU信息如下:"
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器位数: " & objItem.AddressWidth & "位"
If objItem.Architecture = 0 Then
TEXzh(n) = TEXzh(n) & vbCrLf & "平台的处理器的设计:X86 "
ElseIf objItem.Architecture = 1 Then
TEXzh(n) = TEXzh(n) & vbCrLf & "平台的处理器的设计:MIPS "
ElseIf objItem.Architecture = 2 Then
TEXzh(n) = TEXzh(n) & vbCrLf & "平台的处理器的设计:Alpha "
ElseIf objItem.Architecture = 3 Then
TEXzh(n) = TEXzh(n) & vbCrLf & "平台的处理器的设计:PowerPC "
Else
TEXzh(n) = TEXzh(n) & vbCrLf & "平台的处理器的设计:ia64 "
End If
TEXzh(n) = TEXzh(n) & vbCrLf & "用性和状态: " & kyx(objItem.Availability)
TEXzh(n) = TEXzh(n) & vbCrLf & "标签: " & objItem.Caption
TEXzh(n) = TEXzh(n) & vbCrLf & "管理程序错误编码: " & objItem.ConfigManagerErrorCode
TEXzh(n) = TEXzh(n) & vbCrLf & "是否使用用户定义的配置: " & objItem.ConfigManagerUserConfig
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器的当前状态: " & objItem.CpuStatus
TEXzh(n) = TEXzh(n) & vbCrLf & "创建范例类别的名称: " & objItem.CreationClassName
TEXzh(n) = TEXzh(n) & vbCrLf & "当前速度: " & objItem.CurrentClockSpeed & "HZ"
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器的电压: " & objItem.CurrentVoltage & "V"
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器数据宽度: " & objItem.DataWidth & "位"
TEXzh(n) = TEXzh(n) & vbCrLf & "描述: " & objItem.Description
TEXzh(n) = TEXzh(n) & vbCrLf & "DeviceID: " & objItem.DeviceID
TEXzh(n) = TEXzh(n) & vbCrLf & "错误是否已经清除: " & objItem.ErrorCleared
TEXzh(n) = TEXzh(n) & vbCrLf & "错误描述: " & objItem.ErrorDescription
TEXzh(n) = TEXzh(n) & vbCrLf & "外部时钟频率: " & objItem.ExtClock
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器系列类型: " & objItem.Family
TEXzh(n) = TEXzh(n) & vbCrLf & "安装日期: " & objItem.InstallDate
TEXzh(n) = TEXzh(n) & vbCrLf & "2 级高速缓存的大小: " & objItem.L2CacheSize
TEXzh(n) = TEXzh(n) & vbCrLf & "2 级高速缓存的速度: " & objItem.L2CacheSpeed
TEXzh(n) = TEXzh(n) & vbCrLf & "最后一次出错代码: " & objItem.LastErrorCode
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器类型.Level: " & objItem.Level
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器在最后一秒钟内的负载能量: " & objItem.LoadPercentage
TEXzh(n) = TEXzh(n) & vbCrLf & "制造商: " & objItem.Manufacturer
TEXzh(n) = TEXzh(n) & vbCrLf & "最大时钟频率: " & objItem.MaxClockSpeed
TEXzh(n) = TEXzh(n) & vbCrLf & "名称: " & objItem.Name
TEXzh(n) = TEXzh(n) & vbCrLf & "内核总数: " & objItem.NumberOfCores
TEXzh(n) = TEXzh(n) & vbCrLf & "逻辑处理器数: " & objItem.NumberOfLogicalProcessors
TEXzh(n) = TEXzh(n) & vbCrLf & "其他描述: " & objItem.OtherFamilyDescription
TEXzh(n) = TEXzh(n) & vbCrLf & "逻辑设备的 Win32 即插即用设备 ID: " & objItem.PNPDeviceID
TEXzh(n) = TEXzh(n) & vbCrLf & "电源的功能: " & objItem.PowerManagementCapabilities
TEXzh(n) = TEXzh(n) & vbCrLf & "PowerManagementSupported: " & objItem.PowerManagementSupported
TEXzh(n) = TEXzh(n) & vbCrLf & "ProcessorId: " & objItem.ProcessorId
TEXzh(n) = TEXzh(n) & vbCrLf & "ProcessorType: " & objItem.ProcessorType
TEXzh(n) = TEXzh(n) & vbCrLf & "版本: " & objItem.Revision
TEXzh(n) = TEXzh(n) & vbCrLf & "Role: " & objItem.Role
TEXzh(n) = TEXzh(n) & vbCrLf & "芯片插槽种类: " & objItem.SocketDesignation
TEXzh(n) = TEXzh(n) & vbCrLf & "状态: " & objItem.Status
TEXzh(n) = TEXzh(n) & vbCrLf & "StatusInfo: " & objItem.StatusInfo
TEXzh(n) = TEXzh(n) & vbCrLf & "修改等级: " & objItem.Stepping
TEXzh(n) = TEXzh(n) & vbCrLf & "作用系统的创建类名: " & objItem.SystemCreationClassName
TEXzh(n) = TEXzh(n) & vbCrLf & "系统名: " & objItem.SystemName
TEXzh(n) = TEXzh(n) & vbCrLf & "UniqueId: " & objItem.UniqueId
TEXzh(n) = TEXzh(n) & vbCrLf & "CPU 插座信息: " & objItem.UpgradeMethod
TEXzh(n) = TEXzh(n) & vbCrLf & "修订版号: " & objItem.Version
TEXzh(n) = TEXzh(n) & vbCrLf & "处理器的电压能量: " & objItem.VoltageCaps
TEXzh(n) = TEXzh(n) & vbCrLf & ""
n = n + 1
Next
For i = 0 To n - 1
MsgBox TEXzh(i) '显示所有CPU信息 其实个人只有一个,大型电脑多CPU
Next
End Sub
Function kyx(a)
Select Case a
Case 3
kyx = "设备正在运行并且拥有全部能量"
Case 4
kyx = "警告!"
Case 5
kyx = "测试"
Case 10
kyx = "降低"
Case 13
kyx = "节能.未知:设备处于节能模式,但是该设备在这个模式中的准确状态未知"
Case 14
kyx = "节能.降低:设备处于节能模式,但是仍旧运行并且反映出降低的功能"
Case 15
kyx = "待机:设备没有在运行,但是可以“快速”进入全能状态"
Case 17
kyx = "节能。警告:设备虽然处于警告状态,但是还处于节能状态"
Case Else
kyx = "未知"
End Select
End Function
On Error GoTo SysInfoErr
Dim rc As Long
Dim SysInfoPath As String
' 试图从注册表中获得系统信息程序的路径及名称...
If GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALSYSINFO, SysInfoPath) Then
' 试图仅从注册表中获得系统信息程序的路径...
ElseIf GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFOLOC, gREGVALSYSINFOLOC, SysInfoPath) Then
' 已知32位文件版本的有效位置
If (Dir(SysInfoPath & "\MSINFO32.EXE") <> "") Then
SysInfoPath = SysInfoPath & "\MSINFO32.EXE"
' 错误 - 文件不能被找到...
Else
GoTo SysInfoErr
End If
' 错误 - 注册表相应条目不能被找到...
Else
GoTo SysInfoErr
End If
Call Shell(SysInfoPath, vbNormalFocus)
Exit Sub
SysInfoErr:
MsgBox "此时系统信息不可用", vbOKOnly
End Sub