using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
public class Check64or32System
{
/// <summary>
/// 检查系统是32位还是64位
/// </summary>
/// <returns>0运行出错;32表示32位系统;64表示64位操作系统</returns>
public static int Distinguish64or32System()
{
try
{
//得到AddressWidth值
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();
string retVal = string.Empty;
foreach (ManagementObject mObject in mObjectCollection)
{
retVal = mObject["AddressWidth"].ToString();
}
//根据值判断,不能直接返回得到的值,
//32位返回"32",64位会因为CPU而有两个值,"N/A"或"64"
if (retVal == "32")
{
return 32;
}
else
{
return 64;
}
}
catch
{
return 0;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Management;
public class Check64or32System
{
/// <summary>
/// 检查系统是32位还是64位
/// </summary>
/// <returns>0运行出错;32表示32位系统;64表示64位操作系统</returns>
public static int Distinguish64or32System()
{
try
{
//得到AddressWidth值
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();
string retVal = string.Empty;
foreach (ManagementObject mObject in mObjectCollection)
{
retVal = mObject["AddressWidth"].ToString();
}
//根据值判断,不能直接返回得到的值,
//32位返回"32",64位会因为CPU而有两个值,"N/A"或"64"
if (retVal == "32")
{
return 32;
}
else
{
return 64;
}
}
catch
{
return 0;
}
}
}
本文提供了一个使用C#语言编写的程序,用于检查当前运行的计算机系统是32位还是64位,并通过获取处理器的AddressWidth属性来实现这一目标。
468

被折叠的 条评论
为什么被折叠?



