Search Tools Links Login

Get CPU Info


Using GetSystemInfo, inside of kernel32, we can get all kinds of information about the local computer. This example shows how to retrieve the description of the CPU.

Module

'API Structures
Public Type SYSTEM_INFO
    wProcessorArchitecture As Integer
    wReserved As Integer
    dwPageSize As Long
    lpMinimumApplicationAddress As Long
    lpMaximumApplicationAddress As Long
    dwActiveProcessorMask As Long
    dwNumberOfProcessors As Long
    dwProcessorType As Long
    dwAllocationGranularity As Long
    wProcessorLevel As Integer
    wProcessorRevision As Integer
End Type

Public Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

'API Calls
Public Declare Sub GetSystemInfo Lib "kernel32.dll" (lpSystemInfo As SYSTEM_INFO)
Public Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

'API Constants
Public Const PROCESSOR_ARCHITECTURE_ALPHA = 2
Public Const PROCESSOR_ARCHITECTURE_INTEL = 0
Public Const PROCESSOR_ARCHITECTURE_MIPS = 1
Public Const PROCESSOR_ARCHITECTURE_PPC = 3
Public Const PROCESSOR_ARCHITECTURE_UNKNOWN = &HFFFF
Public Const PROCESSOR_INTEL_386 = 386
Public Const PROCESSOR_INTEL_486 = 486
Public Const PROCESSOR_INTEL_PENTIUM = 586
Public Const PROCESSOR_INTEL_PENTIUM2 = 686
Public Const PROCESSOR_INTEL_PENTIUM3 = 786
Public Const PROCESSOR_MIPS_R4000 = 4000
Public Const VER_PLATFORM_WIN32_NT = 2
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
'get a string with the description of the system's processor
Public Function GetProcessorType() As String
    Dim si As SYSTEM_INFO
    Dim os As OSVERSIONINFO

    'retrive the Windows Platform
    os.dwOSVersionInfoSize = Len(os)
    GetVersionEx os
    'retrive the SYSTEM_INFO Structure
    GetSystemInfo si
    Select Case si.wProcessorArchitecture
    'Intel Architecture
    Case PROCESSOR_ARCHITECTURE_INTEL
        Select Case os.dwPlatformId
        Case VER_PLATFORM_WIN32_NT
            Select Case si.wProcessorLevel
            Case 3
                GetProcessorType = "Intel 80386"
                If (si.wProcessorRevision And &HFF00) = &HFF00 Then
                    GetProcessorType = GetProcessorType And " Model " & ((si.wProcessorRevision And &HF0) / &HF) - 10 & " Stepping " & (si.wProcessorRevision And &HF)
                Else
                    GetProcessorType = GetProcessorType And " Stepping " & Chr(Asc("A") + (si.wProcessorRevision And &HFF) / &HFF) & " Stepping " & (si.wProcessorRevision And &HFF)
                End If
            Case 4
                GetProcessorType = "Intel 80486"
                If (si.wProcessorRevision And &HFF00) = &HFF00 Then
                    GetProcessorType = GetProcessorType And " Model " & ((si.wProcessorRevision And &HF0) / &HF) - 10 & " Stepping " & (si.wProcessorRevision And &HF)
                Else
                    GetProcessorType = GetProcessorType And " Stepping " & Chr(Asc("A") + (si.wProcessorRevision And &HFF) / &HFF) & " Stepping " & (si.wProcessorRevision And &HFF)
                End If
            Case 5
                GetProcessorType = "Pentium Model " & (si.wProcessorRevision And &HFF00) \ &HFF & " Stepping " & (si.wProcessorRevision And &HFF)
            Case 6
                GetProcessorType = "Pentium II Model " & (si.wProcessorRevision And &HFF00) \ &HFF & " Stepping " & (si.wProcessorRevision And &HFF)
            Case 7
                GetProcessorType = "Pentium III Model " & (si.wProcessorRevision And &HFF00) \ &HFF & " Stepping " & (si.wProcessorRevision And &HFF)
            End Select
        Case VER_PLATFORM_WIN32_WINDOWS
            Select Case si.dwProcessorType
            Case PROCESSOR_INTEL_386
                GetProcessorType = "Intel 80386"
            Case PROCESSOR_INTEL_486
                GetProcessorType = "Intel 80486"
            Case PROCESSOR_INTEL_PENTIUM
                GetProcessorType = "Pentium"
            Case PROCESSOR_INTEL_PENTIUM2
                GetProcessorType = "Pentium II"
            Case PROCESSOR_INTEL_PENTIUM3
                GetProcessorType = "Pentium III"
            End Select
        End Select
    'MIPS Architecture (only for WinNT)
    Case PROCESSOR_ARCHITECTURE_MIPS
        GetProcessorType = "MIPS R" & si.wProcessorLevel & "000"
    'ALPHA Architecture (only for WinNT)
    Case PROCESSOR_ARCHITECTURE_ALPHA
        GetProcessorType = "Alpha " & si.wProcessorLevel & " Model A" & (si.wProcessorRevision And &HFF00) \ &HFF & " Pass " & (si.wProcessorRevision And &HFF)
    'PPC Architecture (only for WinNT)
    Case PROCESSOR_ARCHITECTURE_PPC
        Select Case si.wProcessorLevel
        Case 1, 3, 4, 20
            GetProcessorType = "PPC 6" & Format(si.wProcessorLevel, "00")
        Case 6
            GetProcessorType = "PPC 603+"
        Case 9
            GetProcessorType = "PPC 604+"
        End Select
        GetProcessorType = GetProcessorType & " Processor Version " & (si.wProcessorRevision And &HFF00) \ &HFF & "." & (si.wProcessorRevision And &HFF)
    End Select
End Function

Usage

Private Sub Command1_Click()
    MsgBox GetProcessorType
End Sub

About this post

Posted: 2019-09-26
By: AndreaTincani
Viewed: 465 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.