How can I programmatically determine my processor type?

后端 未结 7 592
清歌不尽
清歌不尽 2021-01-13 01:03

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

7条回答
  •  情话喂你
    2021-01-13 01:41

    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
    

提交回复
热议问题