Use the Registry to get CPU/Processor Hardware information using VB.NET and Higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

This is a simple article/tip of using the Windows System Registry to access the ‘CentralProcessor’ sub-key and extract information about the computers processor. You can get the cpu’s clockspeed, namestring, model, stepping, etc. Shows two ways to access the registry.

Example use is below.


Visual Basic.NET, Visual Basic 2008, and VB 2010

        'The registry path to get the info we are wanting.
        Dim str As String = "HARDWARE\DESCRIPTION\System\CentralProcessor"

        'Returns how many SubKeys are under “CentralProcessor”.
        'The subKey count under this key =’s the‘total cpu’s your system has installed.
        'My system happens to return 2x subkeys since I have a Dual Core system.
        Dim cpuCount As Integer = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(str, False).SubKeyCount
        '
        'Get and add the values for the first cpu.
        '
        Dim cpuMhz As String = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("~mhz")

        Dim cpuName As String = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("ProcessorNameString")

        Dim cpuVendorID As String = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("VendorIdentifier")

        Dim cpuIdentifier As String = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("Identifier")

Thats all there is to it. You just need to handle the variables that will contain the cpu data extracted. Below is similar example code for VB 05, and higher only since it uses the MY interface to access the registry…


Visual Basic 2005/2008 and VB 2010 Only…

        'The registry path to get the info we are wanting.
        Dim str As String = "HARDWARE\DESCRIPTION\System\CentralProcessor"

        'Returns how many SubKeys are under “CentralProcessor”.
        'The subKey count under this key =’s the‘total cpu’s your system has installed.
        'Of course, 90% or so will only have 1x subkey denoting a‘single cpu system.
        'My system happens to return 2x subkeys since I have a Dual Core system.
        Dim cpuCount As Integer = My.Computer.Registry.LocalMachine.OpenSubKey(str, False).SubKeyCount

        'Get and add the values for the first cpu.

        Dim cpuMhz As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("~mhz")

        Dim cpuName As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("ProcessorNameString")

        Dim cpuVendorID As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("VendorIdentifier")

        Dim cpuIdentifier As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
            "HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("Identifier")

For VB 6.0 it’s not quite this simple to access the registry. Win32 API calls are required to do so. There are examples around the net that shows how to use the Win32 Registry code in VB 6.0. Have fun!

Jason

One thought on “Use the Registry to get CPU/Processor Hardware information using VB.NET and Higher

Leave a Reply