public static UInt16 GetOSAddressWidth()
{
try
{
SelectQuery query = new SelectQuery("select AddressWidth from Win32_Processor");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection moCollection = searcher.Get();
foreach (ManagementObject mo in moCollection)
{
foreach (PropertyData property in mo.Properties)
{
if (property.Name.Equals("AddressWidth"))
{
return Convert.ToUInt16(property.Value);
}
}
}
throw new Exception("Didn't get expected query result from WMI.");
}
catch (Exception ex)
{
throw new Exception("Error occurs in WMI query.", ex.InnerException);
}
}