c shares an example of determining operating system bits

  • 2020-06-03 08:12:02
  • OfStack

In.net 4.5, the judgment operating system does not have to write methods to determine, and there are directly available properties, as shown below:
Environment.Is64BitProcess attribute.NET Framework 4.5

Determines whether the current process is a 64-bit process.

Of course, if it is used.net 4.5 children's shoes before do not have to worry, also can use the following method to realize the determination of the system digit.


private 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)
{

return String.Empty;
}
}


Related articles: