悟生慧

 

C#获取操作系统是32位或64位的代码

注意需添加引用System.Management)

public static string Distinguish64or32System()
{
try
{
string addressWidth = String.Empty;
ConnectionOptions mConnOption = new ConnectionOptions();
ManagementScope mMs = new ManagementScope("\\\\localhost", mConnOption);
ObjectQuery mQuery = new ObjectQuery("select AddressWidth from Win32_Processor");
ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(mMs, mQuery);
ManagementObjectCollection mObjectCollection = mSearcher.Get();
foreach (ManagementObject mObject in mObjectCollection)
{
addressWidth = mObject["AddressWidth"].ToString();
}
return addressWidth;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return String.Empty;
}
}
View Code

 

posted on 2013-08-15 16:30  悟生慧  阅读(1007)  评论(0编辑  收藏  举报

导航