Home » excel » excel – Get Processor.Name from an object

excel – Get Processor.Name from an object

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to get processor information, specially name like Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz.

Searching web I found a function which gives me all the properties of processor using a for-each loop.

Below is full function and a sample link is also attached. I am trying to get only name property. How do I get name property without for-each loop or in other method so that I can get processor name only. I will use this code to collect Hard Disk, RAM, Processor information but not all information only name, size, etc.

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
How to&Answers:

Simplest way to get the name of the processor

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

When I run the code I get 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

You can read the name directly from the registry then?

Sub ProcessorName()
    Dim objWsScript As Object

    Set objWsScript = CreateObject("WScript.Shell")

    Debug.Print objWsScript.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor
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 
\ProcessorNameString") End Sub