我正在尝试获取处理器信息,特别是像英特尔(R)Core(商标)i5-7200UCPU@ 2.50GHz。
搜索web时,我发现了一个函数,它给了我使用for-each循环的处理器的所有属性。
下面是完整的功能,并附上一个示例链接。我只想得到名字的财产。如何在没有for-每个循环或其他方法的情况下获得name property,以便只获得处理器名。我将使用此代码收集硬盘、内存、处理器信息,但并不是所有信息都是名称、大小等。
Public oWMISrvEx As Object 'SWbemServicesEx
Public oWMIObjSet As Object 'SWbemServicesObjectSet
Public oWMIObjEx As Object 'SWbemObjectEx
Public oWMIProp As Object 'SWbemProperty
Public sWQL As String 'WQL Statement
Public n
Sub ProcessorWMI()
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Processor")
sWQL = "Select * From Win32_Processor"
Set oWMISrvEx = GetObject("winmgmts:root/CIMV2")
Set oWMIObjSet = oWMISrvEx.ExecQuery(sWQL)
intRow = 2
strRow = Str(intRow)
sht.Range("A1").Value = "Name"
sht.Cells(1, 1).Font.Bold = True
sht.Range("B1").Value = "Value"
sht.Cells(1, 2).Font.Bold = True
For Each oWMIObjEx In oWMIObjSet
For Each oWMIProp In oWMIObjEx.Properties_
If Not IsNull(oWMIProp.Value) Then
If IsArray(oWMIProp.Value) Then
For n = LBound(oWMIProp.Value) To UBound(oWMIProp.Value)
Debug.Print oWMIProp.Name & "(" & n & ")", oWMIProp.Value(n)
sht.Range("A" & Trim(strRow)).Value = oWMIProp.Name
sht.Range("B" & Trim(strRow)).Value = oWMIProp.Value(n)
sht.Range("B" & Trim(strRow)).HorizontalAlignment = xlLeft
intRow = intRow + 1
strRow = Str(intRow)
Next
Else
sht.Range("A" & Trim(strRow)).Value = oWMIProp.Name
sht.Range("B" & Trim(strRow)).Value = oWMIProp.Value
sht.Range("B" & Trim(strRow)).HorizontalAlignment = xlLeft
intRow = intRow + 1
strRow = Str(intRow)
End If
End If
Next
Next
End Sub发布于 2018-09-28 06:33:48
获取处理器名称的最简单方法
Sub ProcessorName()
Dim objPross As Object, cpu As Object
Set objPross = GetObject("WinMgmts:").instancesof("Win32_Processor")
For Each cpu In objPross
Debug.Print cpu.Name
Next
End Sub当我运行代码时,我会得到Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz。
这将达到我的目的。不管怎样,在您的代码中有像名称这样的对象cpu属性列表吗?- Harun24HR 14秒前
那么您可以直接从注册表中读取名称吗?
Sub ProcessorName()
Dim objWsScript As Object
Set objWsScript = CreateObject("WScript.Shell")
Debug.Print objWsScript.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\ProcessorNameString")
End Subhttps://stackoverflow.com/questions/52549442
复制相似问题