gpt4 book ai didi

excel - 从对象中获取 Processor.Name

转载 作者:行者123 更新时间:2023-12-04 22:31:17 25 4
gpt4 key购买 nike

我正在尝试获取处理器信息,特别是像 这样的名称Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz .

搜索网络我发现了一个函数,它使用 for-each 为我提供了处理器的所有属性环形。

以下是完整功能,还附有示例链接。我试图只获得名称属性。我如何获得 name property没有 for-each 循环或其他方法,因此我只能获取处理器名称。我将使用此代码收集硬盘、内存、处理器 信息,但不是所有信息,只有名称、大小等。

Sample File Download Link

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

最佳答案

获取处理器名称的最简单方法

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 .

This will serve my purpose. Anyway is there any list of property of object cpu in your code like name? – Harun24HR 14 secs ago



你可以直接从注册表中读取名称吗?
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 Sub

关于excel - 从对象中获取 Processor.Name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52549442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com