2013-05-04 140 views
2

我要檢測的運算能力的CPU(尤其是如果它是一個32/64位CPU)如何檢測,如果CPU是32位還是64位

的機器在32位操作系統上運行(操作系統)我想檢測這些機器是否能夠安裝64位操作系統。

(順便說一句:在這一點上,我知道如何檢測內核的數量...)

+0

這也許[問題](http://stackoverflow.com/questions/2017409/right-way-to-detect-cpu-architecture)可以幫助您檢測CPU架構。 – ahawkthomas 2013-05-04 10:02:37

+0

看看[這裏] [1]和[這裏] [2],他們已經回答 [1]:http://stackoverflow.com/questions/1542213/how-to-find-的用戶號碼的CPU的型芯 - 經由網-C [2]:http://stackoverflow.com/questions/1817268/how-can-i-determine-programmatically-whether-on-multi-core -hyperthreading-or-mu – Solaflex 2013-05-04 10:02:48

+0

@ahawkthomas:我認爲答案說明了一些關於當前安裝的操作系統,而不是CPU本身。 – 2013-05-04 10:05:30

回答

2

您可以使用WMI以獲取有關每個CPU更多的細節,following properties are available in the Win32_Processor class

您可以使用以下代碼來獲得每個屬性的值:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor"); 
ManagementObjectCollection cpus = searcher.Get() 
foreach (ManagementObject queryObj in cpus) 
{ 
    Console.WriteLine("AddressWidth : {0}", queryObj["AddressWidth"]); //On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64. 
    Console.WriteLine("DataWidth: {0}", queryObj["DataWidth"]); //On a 32-bit processor, the value is 32 and on a 64-bit processor it is 64 
    Console.WriteLine("Architecture: {0}", queryObj["Architecture"]); //Processor architecture used by the platform 
} 

我不知道,如果AddressWidth是,你需要確定是否爲CPU能夠與64位操作系統或不

正確的屬性
+0

嗯...那個「位」的部分是,我與正如我所提到煩心事......一:我知道如何尋找#cores。 – 2013-05-04 10:20:57

+0

因爲我告訴你,你可以使用'AddressWidth'屬性來獲取是否如果CPU可以支持64位操作系統或沒有,對不起,我接着說:NumberOfCores'作爲例子在我的代碼,我只是編輯它來寫的'AddressWidth ' – 2013-05-04 10:31:22

+0

的'AddressWidth'表示操作系統的架構,但是你可以使用'DataWidth'屬性來獲取CPU架構,檢查[MSDN文檔(http://msdn.microsoft.com/en-us/library/窗戶/桌面/ aa394373%28V = vs.85%29.aspx) – 2013-05-04 10:42:36

0

或者如果你想玩所有的WMI課程,你可以使用WMI Code Creator

我以前用過它,它幫了我很多。

相關問題