基本信息
源码名称:C# 更改webbrower的ie调用版本(修改注册表实现)
源码大小:0.07M
文件格式:.zip
开发语言:C#
更新时间:2016-04-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Management;
namespace RegistryVs
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            try
            {
                is64 = GetBit();
                InitIEdic();
                GetIEValue(out IENum, out IEPath, out maxIeVesion, out maxIeValue, is64);


                foreach (KeyValuePair<int, RadioButton> item in ibr)
                {
                    if (item.Key > IENum)
                    {
                        item.Value.Visible = false;
                    }
                    if (item.Key == IENum)
                    {
                        item.Value.BackColor = lbBest.BackColor;
                    }
                }
                if (is64 == true)
                {
                    IEBrowserPath = @"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
                }
                else
                {
                    IEBrowserPath = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
                }
                openFileDialog1.Filter = "|*.exe";

                lbCurIE.Text = maxIeVesion;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Source, "操作提示");
            }

        }


        public bool is64 = false;

        public int IENum = 7;

        public string maxIeVesion;

        public UInt16 maxIeValue;

        public string IEPath;


        public string IEBrowserPath;

        private bool GetBit()
        {
            try
            {
                string addressWidth = String.Empty;
                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();
                foreach (ManagementObject mObject in mObjectCollection)
                {
                    addressWidth = mObject["AddressWidth"].ToString();
                }
                if (addressWidth == "32")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        private UInt16 GetSetIeVersion()
        {
            int ienum = 7; ;
            foreach (KeyValuePair<int, RadioButton> item in ibr)
            {
                if (item.Value.Visible == true && item.Value.Checked == true)
                {
                    ienum = item.Key;
                }
            }
            return IeDic[ienum];
        }


        public void GetPath(out string path, out string filename)
        {
            string fullname = this.textBox1.Text;
            fullname = fullname.Replace("/", "\\");
            int index = fullname.LastIndexOf('\\');
            path = fullname.Substring(0, index);
            filename = fullname.Substring(index   1, fullname.Length - index - 1);
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //RegisterObj r = new RegisterObj();
            string path;
            string name;
            GetPath(out path, out name);
            if (!name.EndsWith(".exe"))
            {
                name = name   ".exe";
            }

            //string sb;
            //string p2;

            //if (is64 == true)
            //{
            //    //sb = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths";
            //    p2 = @"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
            //}
            //else
            //{
            //    //sb = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths";
            //    p2 = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
            //}


            //r.CreateSubKey(sb   @"\"   name, RegDomain.LocalMachine);

            //RegisterObj r2 = new RegisterObj(sb   @"\"   name, RegDomain.LocalMachine);

            //if (r2.IsSubKeyExist())
            //{
            //    r2.WriteRegeditKey("Path", path);
            //    r2.WriteRegeditKey("", path   @"\"   name);
            //}



            RegisterObj r3 = new RegisterObj(IEBrowserPath, RegDomain.LocalMachine);
            if (IeNull.Checked == true)
            {
                r3.DeleteRegeditKey(name);
                lbIeSet.Text = "无";
            }
            else
            {
                UInt16 setIeVersion = GetSetIeVersion();
                r3.WriteRegeditKey(name, setIeVersion, RegValueKind.DWord);
                lbIeSet.Text = "IE"   VerDic[setIeVersion];
            }



            MessageBox.Show("注册成功");
        }

        private void GetIEValue(out int ieNum, out string iePath, out string version, out UInt16 ie, bool is64)
        {
            if (is64)
            {
                iePath = @"software\Wow6432Node\Microsoft\Internet Explorer";
            }
            else
            {
                iePath = @"software\Microsoft\Internet Explorer";
            }
            RegistryKey mreg;
            mreg = Microsoft.Win32.Registry.LocalMachine;
            mreg = mreg.CreateSubKey(iePath);
            version = (String)mreg.GetValue("Version");
            string[] vs = version.ToString().Split('.');
            if (vs.Length > 0)
            {
                ieNum = Convert.ToInt32(vs[0]);
            }
            else
            {
                ieNum = 7;
            }
            if (ieNum >= 7 && ieNum <= 11)
            {

            }
            else
            {
                ieNum = 7;
            }

            ie = IeDic[ieNum];


            mreg.Close();
        }


        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();

        }


        private Dictionary<int, UInt16> IeDic = new Dictionary<int, UInt16>();

        public Dictionary<UInt16, int> VerDic = new Dictionary<UInt16, int>();


        public Dictionary<RadioButton, int> rbi = new Dictionary<RadioButton, int>();

        public Dictionary<int, RadioButton> ibr = new Dictionary<int, RadioButton>();

        public void AddDic(int ie, UInt16 ver, RadioButton rb)
        {
            IeDic.Add(ie, ver);
            VerDic.Add(ver, ie);
            rbi.Add(rb, ie);
            ibr.Add(ie, rb);
        }

        public void InitIEdic()
        {

            /*
                11001 (0x2EDF) Internet Explorer 11. Webpages are displayed in IE11 Standards mode, regardless of the !DOCTYPE directive
                11000 (0x2AF8) :Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode
                10000 (0x2710) :Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
                10001 (0x2AF7) :Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive.
                9999 (0x270F) :Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
                9000 (0x2328) :Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
                8888 (0x22B8) :Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
                8000 (0x1F40) :Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
                7000 (0x1B58) :Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
             * */


            AddDic(7, 7000, rdIE7);
            AddDic(8, 8888, rdIE8);
            AddDic(9, 9999, rdIE9);
            AddDic(10, 10001, rdIE10);
            AddDic(11, 11001, rdIE11);

        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            if (!openFileDialog1.FileName.EndsWith(".exe"))
            {
                MessageBox.Show("请选择主程序注册,必须为exe文件");
                this.textBox1.Text = "";
                lbIeSet.Text = "无";
                return;
            }
            else
            {
                this.textBox1.Text = openFileDialog1.FileName;

                RegisterObj r3 = new RegisterObj(IEBrowserPath, RegDomain.LocalMachine);
                string path;
                string name;
                GetPath(out path, out name);
                if (!name.EndsWith(".exe"))
                {
                    name = name   ".exe";
                }
                bool exists = r3.IsRegeditKeyExist(name);
                if (exists == true)
                {
                    UInt16 curversion = Convert.ToUInt16(r3.ReadRegeditKey(name));
                    lbIeSet.Text = GetIeString(curversion);

                    int ienum = VerDic[curversion];

                    if (ibr.ContainsKey(ienum) && ibr[ienum].Visible == true)
                    {
                        ibr[ienum].Checked = true;
                    }
                    else
                    {
                        IeNull.Checked = true;
                    }
                }
                else
                {
                    ibr[7].Checked = true;

                    lbIeSet.Text = "IE7";

                }

            }
        }

        public string GetIeString(UInt16 iedbversion)
        {
            if (VerDic.ContainsKey(iedbversion))
            {
                return "IE"   VerDic[iedbversion];
            }
            else
            {
                return "未知";
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}