How can I programmatically determine my processor

2020-03-19 03:46发布

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

7条回答
Bombasti
2楼-- · 2020-03-19 03:56

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
查看更多
家丑人穷心不美
3楼-- · 2020-03-19 03:58

What's usually more important than the underlying processor is what mode the OS is running in, in ADDITION to the processor that's installed on the host.

Examine the output of "uname -p" (or uname(2))

Intel adopted AMD's extensions for 64-bit instructions so a value of "x86_64" means you're running either an Intel or AMD 64-bit processor, otherwise you're running the regular x86 ISA.

查看更多
ら.Afraid
4楼-- · 2020-03-19 04:00

In Java you shouldn't need to know. ;)

查看更多
\"骚年 ilove
5楼-- · 2020-03-19 04:01

cpu-z is the program you want, it will tell you which processor you have and what extensions it supports

查看更多
我想做一个坏孩纸
6楼-- · 2020-03-19 04:12

cat /proc/cpuinfo

查看更多
Melony?
7楼-- · 2020-03-19 04:20

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
查看更多
登录 后发表回答