-
Oct 23rd, 2011, 01:47 AM
#1
Thread Starter
Addicted Member
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
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
-
Oct 23rd, 2011, 07:25 AM
#2
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
-
Oct 23rd, 2011, 07:26 AM
#3
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.
-
Oct 23rd, 2011, 07:36 AM
#4
Thread Starter
Addicted Member
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
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|