在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 更改webbrower的ie调用版本(修改注册表实现)

C# 更改webbrower的ie调用版本(修改注册表实现)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.07M
  • 下载次数:24
  • 浏览次数:454
  • 发布时间:2016-04-11
  • 实例类别:C#语言基础
  • 发 布 人:ztz070306011
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 操作 web 注册表

实例介绍

【实例简介】

【实例截图】

【核心代码】

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)
        {

        }
    }
}

标签: 操作 web 注册表

实例下载地址

C# 更改webbrower的ie调用版本(修改注册表实现)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 陌生人 发表于: 2016-06-04 09:30 00
有帮助

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警