现在的位置: 首页 > 综合 > 正文

获取系统是32位还是64位

2014年02月25日 ⁄ 综合 ⁄ 共 892字 ⁄ 字号 评论关闭
        public static UInt16 GetOSAddressWidth()
        {
            try
            {
                SelectQuery query = new SelectQuery("select AddressWidth from Win32_Processor");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                ManagementObjectCollection moCollection = searcher.Get();
                foreach (ManagementObject mo in moCollection)
                {
                    foreach (PropertyData property in mo.Properties)
                    {
                        if (property.Name.Equals("AddressWidth"))
                        {
                            return Convert.ToUInt16(property.Value);
                        }
                    }
                }

                throw new Exception("Didn't get expected query result from WMI.");
            }
            catch (Exception ex)
            {
                throw new Exception("Error occurs in WMI query.", ex.InnerException);
            }
        } 

                    UInt16 os = GetOSAddressWidth();
                    string BarCode="";
                    if (os == 64)
                    {
                        RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Clear");

                        BarCode = rk.GetValue("IsBarCodeWaterMark").ToString();
                        rk.Close();
                    }
                    if (os == 32)
                    {
                        RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\Clear");

                        BarCode = rk.GetValue("IsBarCodeWaterMark").ToString();
                        rk.Close();

                    }

抱歉!评论已关闭.