C# 获取当前操作系统是x64(64位)还是x32(32位)

C# 获取当前操作系统是x64(64位)还是x32(32位)
using System;
using System.Management;

namespace DemoConsole
{
    class Program
    {
        // 引入System.Management
        static void Main(string[] args)
        {
            Console.WriteLine("OSBit : {0}", GetOSBit());

            Console.Read();
        }

        /// <summary>
        /// 获取当前操作系统是x64(64位)还是x32(32位)
        /// </summary>
        /// <returns></returns>
        public static int GetOSBit()
        {
            try
            {
                string addressWidth = "";
                ConnectionOptions connectionOptions = new ConnectionOptions();
                ManagementScope managementScope = new ManagementScope(@"\\localhost", connectionOptions);
                ObjectQuery objectQuery = new ObjectQuery("select AddressWidth from Win32_Processor");
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery);
                ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
                foreach (ManagementObject managementObject in managementObjectCollection)
                {
                    addressWidth = managementObject["AddressWidth"].ToString();
                }

                return int.Parse(addressWidth);
            }
            catch
            {
                throw;
            }
        }
    }
}


作者最新文章
css 去掉a标签超链接的虚线框的方法, 何去除超链接点击时的虚线?
C# 创建、保存、写入无 bom 的 utf-8 编码文件
ASP.NET aspx 后台代码执行前台js脚本, 弹出消息, 调用函数
ASP.NET aspx 后台代码控制前台显示、隐藏
js 打印功能