简体   繁体   English

如何以编程方式确定我的处理器类型?

[英]How can I programmatically determine my processor type?

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

On Windows Systems you can get the environment variable PROCESSOR_ARCHITECTURE. 在Windows系统上,您可以获取环境变量PROCESSOR_ARCHITECTURE。 Here is an MSDN article explaining the values that can be returned. 这是一篇MSDN文章,解释了可以返回的值。

 PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_ARCHITECTURE=IA64 PROCESSOR_ARCHITECTURE=x86 

VBScript, checking the PROCESSOR_ARCHITECTURE environment variable: VBScript,检查PROCESSOR_ARCHITECTURE环境变量:

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: VBScript,使用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#: 在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)) 检查“uname -p”(或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. 英特尔采用了AMD的64位指令扩展,因此值“x86_64”意味着您运行的是Intel或AMD 64位处理器,否则您将运行常规x86 ISA。

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

In Java you shouldn't need to know. 在Java中,您不需要知道。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式确定是在多核,超线程还是在多处理器上? - How can I determine programmatically whether on multi-core, hyperthreading or multi-processor? 如何以编程方式确定下一步可插入的XML元素? - How can I programmatically determine the XML elements that can be inserted next? 如何以编程方式确定是否需要TFS WorkItem字段? - How can I programmatically determine if a TFS WorkItem field is required? 如何以编程方式确定事件ID的描述 - How can I programmatically determine the description of an Event ID 如何以编程方式确定Windows任务栏是否隐藏? - How can I determine programmatically whether the Windows taskbar is hidden or not? 如何以编程方式确定Jet数据库引擎类型 - How to determine Jet database Engine Type programmatically 如何确定 object 是否可以将 ToString 转换为值或类型名称? - How can I determine if an object can ToString into value or type name? 如何通过protobuf-net以编程方式确定类型是否可以本机序列化? - How do I programmatically determine if a type is natively serializable by protobuf-net? 在C#中确定操作系统和处理器类型 - Determine operating system and processor type in C# 如何使用“is”来确定参数的值是否为类的类型? - How can I use "is" to determine if the value of a parameter is a type of class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM