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;
            }
        }
    }
}


作者最新文章
Winform TextBox (文本框) 密码输入框, 输入内容显示*号 (星号)
Winform 启动前弹出登录界面, 登录成功之后再显示主界面
C# 字符串string和字符数组char[]的相互转换
C# 字符串倒序输出, 实现字符串倒序的方法
Winform 如何从 TextBox(文本框) 控件读取每一行数据到数组