判断操作系统是32位还是64位

发布时间:2016-12-29 22:25 作者:独孤剑 阅读:228


引入System.Management,再引用


usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Management;

 

namespaceWindowsFormsApplication1

{

   public partialclass Form1: Form

   {

       public Form1()

       {

            InitializeComponent();

       }

 

       private voidbutton1_Click(object sender, EventArgs e)

       {

            //AddressWidth返回值

            //32bitOS64bit OS

            //32bitCPUAddressWidth = 32N/A

            //64bitCPUAddressWidth = 32AddressWidth = 64

            textBox1.Text =Judgment64or32System().ToString();

       }

       /// <summary>

       /// 判断当前系统是32位的还是64

       /// </summary>

       /// <returns></returns>

       public staticstring Judgment64or32System()

       {

            try

            {

                stringaddressWidth = String.Empty;

                ConnectionOptionsmConnOption = new ConnectionOptions();

                ManagementScopemMs = new ManagementScope("\\\\localhost", mConnOption);

                ObjectQuerymQuery = new ObjectQuery("select AddressWidth from Win32_Processor");

                ManagementObjectSearchermSearcher = new ManagementObjectSearcher(mMs,mQuery);

                ManagementObjectCollectionmObjectCollection = mSearcher.Get();

                foreach(ManagementObject mObject in mObjectCollection)

                {

                    addressWidth = mObject["AddressWidth"].ToString();

                }

                returnaddressWidth;//返回值

            }

            catch(Exception ex)

            {

                Console.WriteLine(ex.Message.ToString());

                returnString.Empty;

            }

       }

   }

}

微信打赏, 微信扫一扫

支付宝打赏, 支付宝扫一扫

如果文章对您有帮助,欢迎给作者打赏

作者最新文章
拜登称政府正调查燃油公司黑客攻击事件 确定该公司网络被勒索软件感染
云南大理森林消防直升机坠入洱海:4名机组人员不幸遇难
jquery $.ajax()方法参数详解
java 使用 itext 导出 PDF 文本绝对定位, itext 绝对定位的方法
杭州野生动物世界“金钱豹出逃”发布致歉声明
企业信息查询系统