简体   繁体   中英

How can I programmatically determine my processor type?

如何以编程方式确定我的机器是x86,x64还是IA64?

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 

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

In C#:

using System;
using Microsoft.Win32;

  class Class1
  {
    static void Main(string[] args)
    {
      RegistryKey RegKey = Registry.LocalMachine;
      RegKey = RegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
      Object cpuSpeed = RegKey.GetValue("~MHz");
      Object cpuType  = RegKey.GetValue("VendorIdentifier");
      Console.WriteLine("You have a {0} running at {1} MHz.",cpuType,cpuSpeed);
    }
  }

cat / proc / cpuinfo

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.

cpu-z是你想要的程序,它会告诉你你拥有哪个处理器以及它支持哪些扩展

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM