-
Getting CPU Name
So far I have only been able to get an accurate name for the CPU via the registry. Although I am not sure if the key will always be:
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
Specifically I am not sure if this will work on CPUs with only one or dual core?
I have tested it on WinXP and 7 with quad cores and it seems to work.
Declarations:
Code:
'----------------------------------------
' Declarations for registry read for CPU name
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const REG_SZ = 1
Function:
Code:
Public Function regCPUName() As String
Dim Hkey As Long, StrValue As String, LenValue As Long, a, i&
' open the hardware key in local machine
Call RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\DESCRIPTION\System\CentralProcessor\0", Hkey&)
' determine the length of string returned via lenvalue
Call RegQueryValueEx(Hkey&, "ProcessorNameString", 0&, REG_SZ, vbNullString, LenValue&)
' make string to hold the key value
StrValue$ = Space$(LenValue)
' get the registry value
Call RegQueryValueEx(Hkey&, "ProcessorNameString", 0&, REG_SZ, ByVal StrValue$, Len(StrValue$))
Call RegCloseKey(Hkey&)
' finally remove any multiple spaces in the string
a = Split(StrValue, " ")
For i = 0 To UBound(a)
If Len(a(i)) Then regCPUName = regCPUName & a(i) & " "
Next i
End Function
Called like this:
Code:
Private Sub Command1_Click()
MsgBox regCPUName
End Sub
-
Re: Getting CPU Name
Hmm, not sure if this is a question or not. Here's
another way with a little less code
Code:
Option Explicit
Private Sub Form_Load()
Dim WMI, Col, Obj
Dim Str As String
Set WMI = GetObject("WinMgmts:")
Set Col = WMI.ExecQuery("Select * from Win32_Processor")
For Each Obj In Col
Str = Str & "Manufacturer: " & Obj.Manufacturer & vbCrLf
Str = Str & "Description: " & Obj.Description & vbCrLf
Str = Str & "Name: " & Obj.Name & vbCrLf
Str = Str & "Speed: " & Obj.MaxClockSpeed
Next
Debug.Print Str
End Sub
-
Re: Getting CPU Name
You can only get back different names if the computer has multiple CPUs. In most cases even then you get the same name back for /0, /1, etc. because most multi-CPU motherboards require identical CPUs (or darned close).
So yes, in a single-CPU, single-core, non-hyperthreading system /0 is still good. It should be a very rare system that has a motherboard allowing CPU 0 to be vacant.
ProcessorNameString isn't really very valuable in an application, but you could use it as one of several inputs into a "machine fingerprint hash" to be used in a software copy protection scheme.
WMI kind of stinks in an application, since users can disable it in many scenarios.
-
Re: Getting CPU Name
I can confim your info dilettante, it looks like a single core cpus and non intel cpus should still work via:
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
source: http://www.liutilities.com/products/.../tweaks/10019/
I didn't think of dual cpu systems i.e 8 core+ systems, even so they would most probably include 2x the same cpu, so I should be ok on that issue.
VBClassicRocks, the problem I have is that on my machine when I run that code I get:
Manufacturer: GenuineIntel
Description: x86 Family 6 Model 23 Stepping 7
Name: Intel Pentium III Xeon processor
Speed: 2333
Where as from the registry I get the correct CPU name: Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz