How can I programmatically determine my processor type?

10,204

Solution 1

On Windows Systems you can get the environment variable PROCESSOR_ARCHITECTURE. Here is an MSDN article explaining the values that can be returned.

PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_ARCHITECTURE=IA64
PROCESSOR_ARCHITECTURE=x86

Solution 2

VBScript, checking the PROCESSOR_ARCHITECTURE environment variable:

Set oShell = CreateObject("WScript.Shell")
Set oEnv = oShell.Environment("System")
Select Case LCase(oEnv("PROCESSOR_ARCHITECTURE"))
  Case "x86"
    ' x86
  Case "amd64"
    ' amd64
  Case "ia64"
    ' ia64
  Case Else
    ' other
End Select

VBScript, using WMI:

Const PROCESSOR_ARCHITECTURE_X86  = 0
Const PROCESSOR_ARCHITECTURE_IA64 = 6
Const PROCESSOR_ARCHITECTURE_X64  = 9

strComputer = "."

Set oWMIService = GetObject("winmgmts:" & _
    "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessors = oWMIService.ExecQuery("SELECT * FROM Win32_Processor")

For Each oProcessor In colProcessors
  Select Case oProcessor.Architecture
    Case PROCESSOR_ARCHITECTURE_X86
      ' x86
    Case PROCESSOR_ARCHITECTURE_X64
      ' x64
    Case PROCESSOR_ARCHITECTURE_IA64
      ' ia64
    Case Else
      ' other
  End Select
Next
Share:
10,204

Related videos on Youtube

Artem Shmatkov
Author by

Artem Shmatkov

Getting into Rust these days

Updated on April 19, 2022

Comments

  • Artem Shmatkov
    Artem Shmatkov about 2 years

    How can I determine programmatically whether my machine is an x86, x64 or an IA64?

    • Admin
      Admin almost 15 years
      You could open up the computer and look at the CPU. Are you looking for a code answer?
    • Sean Bright
      Sean Bright almost 15 years
      Strange. The OP didn't mention C#, VBScript, or Java.
    • msvcyc
      msvcyc almost 15 years
      check this SO question -> stackoverflow.com/questions/824877/…
  • Admin
    Admin almost 15 years
    Not sure why this got marked down, type into a command line echo % PROCESSOR_ARCHITECTURE%
  • Artem Shmatkov
    Artem Shmatkov almost 15 years
    exactly what I was looking for!
  • galaktor
    galaktor over 14 years
    Instead of getting "VendorIdentifier" you might want to get "ProcessorNameString" which contains the vendors common model name.
  • Ben Voigt
    Ben Voigt almost 13 years
    The MSDN article suggests that this tells you the OS architecture, not the processor type (you can have x86 OS on x86_64 processor).