windows 如何获取处理器和主板 ID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2436221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Processor and Motherboard Id?
提问by Frank
I used the code from http://www.rgagnon.com/javadetails/java-0580.htmlto get Motherboard Id, but the result is "null".
我使用来自http://www.rgagnon.com/javadetails/java-0580.html的代码来获取主板 ID,但结果为“空”。
How can that be?
Also I modified the code a bit to look like this to get ProcessorId:
"Set objWMIService = GetObject(\"winmgmts:\\.\root\cimv2\")\n"+ "Set colItems = objWMIService.ExecQuery _ \n"+ " (\"Select * from Win32_Processor\") \n"+ "For Each objItem in colItems \n"+ " Wscript.Echo objItem.ProcessorId \n"+ " exit for ' do the first cpu only! \n"+ "Next \n";
怎么可能?
此外,我对代码进行了一些修改以获取 ProcessorId:
"Set objWMIService = GetObject(\"winmgmts:\\.\root\cimv2\")\n"+ "Set colItems = objWMIService.ExecQuery _ \n"+ " (\"Select * from Win32_Processor\") \n"+ "For Each objItem in colItems \n"+ " Wscript.Echo objItem.ProcessorId \n"+ " exit for ' do the first cpu only! \n"+ "Next \n";
The result is something like: ProcessorId = BFEBFBFF00010676
结果是这样的: ProcessorId = BFEBFBFF00010676
On http://msdn.microsoft.com/en-us/library/aa389273%28VS.85%29.aspxit says:
在http://msdn.microsoft.com/en-us/library/aa389273%28VS.85%29.aspx 上,它说:
ProcessorId:Processor information that describes the processor features. For an x86 class CPU, the field format depends on the processor support of the CPUID instruction. If the instruction is supported, the property contains 2 (two) DWORD formatted values. The first is an offset of 08h-0Bh, which is the EAX value that a CPUID instruction returns with input EAX set to 1. The second is an offset of 0Ch-0Fh, which is the EDX value that the instruction returns. Only the first two bytes of the property are significant and contain the contents of the DX register at CPU reset—all others are set to 0 (zero), and the contents are in DWORD format.
ProcessorId:描述处理器特性的处理器信息。对于 x86 类 CPU,字段格式取决于 CPUID 指令的处理器支持。如果支持该指令,则该属性包含 2(两个)DWORD 格式的值。第一个是08h-0Bh的偏移量,这是CPUID指令在输入EAX设置为1时返回的EAX值。第二个是0Ch-0Fh的偏移量,这是指令返回的EDX值。只有该属性的前两个字节是重要的,并且包含 CPU 复位时 DX 寄存器的内容——所有其他字节都设置为 0(零),内容为 DWORD 格式。
I don't quite understand it; in plain English, is it unique or just a number for this class of processors, for instance all Intel Core2 Duo P8400 will have this number?
我不太明白;用简单的英语来说,它是唯一的还是只是此类处理器的一个数字,例如所有 Intel Core2 Duo P8400 都会有这个数字?
回答by Macmade
With eax set to 1, the cpuid opcode will return the processor type, familly, etc in eax, and the processor features in edx. So what you will get is not something unique, like the CPU serial number.
eax 设置为 1 时,cpuid 操作码将在 eax 中返回处理器类型、系列等,在 edx 中返回处理器功能。所以你得到的不是唯一的东西,比如 CPU 序列号。