//通常情况下,我们直接调用C#的webBrowser控件,默认的浏览器内核是IE7。  那么如何修改控件调用的默认浏览器版本呢?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32; namespace TaoMoban
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{ public MainWindow()
{
InitializeComponent(); try
{
int IEversion = GetBrowserVersion();
if (IEversion >= 11)
{
SetWebBrowserFeatures(11);
}
else {
MessageBox.Show("你的浏览器版本(" + IEversion + ")太低,本程序需要系统安装IE11以上版本浏览器");
} }
catch(Exception ex) { MessageBox.Show("" +ex.Message );
} } /// <summary>
/// 修改注册表信息来兼容当前程序
/// </summary>
static void SetWebBrowserFeatures(int ieVersion)
{ //获取程序及名称
var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
//得到浏览器的模式的值
UInt32 ieMode = GeoEmulationModee(ieVersion);
var featureControlRegKey = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\";
//设置浏览器对应用程序(appName)以什么模式(ieMode)运行
Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION",
appName, ieMode, RegistryValueKind.DWord);
//不晓得设置有什么用
Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION",
appName, 1, RegistryValueKind.DWord);
}
/// <summary>
/// 获取浏览器的版本
/// </summary>
/// <returns></returns>
static int GetBrowserVersion()
{
int browserVersion = 0;
using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
RegistryKeyPermissionCheck.ReadSubTree,
System.Security.AccessControl.RegistryRights.QueryValues))
{
var version = ieKey.GetValue("svcVersion");
if (null == version)
{
version = ieKey.GetValue("Version");
if (null == version)
throw new ApplicationException("Microsoft Internet Explorer is required!");
}
int.TryParse(version.ToString().Split('.')[0], out browserVersion);
}
//如果小于7
if (browserVersion < 7)
{
throw new ApplicationException("不支持的浏览器版本!IE" + browserVersion);
}
return browserVersion;
}
/// <summary>
/// 通过版本得到浏览器模式的值
/// </summary>
/// <param name="browserVersion"></param>
/// <returns></returns>
static UInt32 GeoEmulationModee(int browserVersion)
{
UInt32 mode = 11000; // Internet Explorer 11
switch (browserVersion)
{
case 7:
mode = 7000; // Internet Explorer 7
break;
case 8:
mode = 8000; // Internet Explorer 8
break;
case 9:
mode = 9000; // Internet Explorer 9
break;
case 10:
mode = 10000; // Internet Explorer 10.
break;
case 11:
mode = 11000; // Internet Explorer 11
break;
}
return mode;
} } }

  

c# 设置IE浏览器版本运行程序-设置webBrowser对应的IE内核版本来运行的更多相关文章

  1. mysql datetime设置now()无效,直接用程序设置默认值比较好

    mysql datetime设置now()无效的,没有此用法,datetime类型不能设置函数式默认值,只能通过触发器等来搞.想设置默认值,只能使用timestamp类型,然后默认值设置为:CURRE ...

  2. selenium设置Chrome浏览器不出现通知,设置代理IP

    from selenium import webdriver PROXY = "" chrome_options = webdriver.ChromeOptions() prefs ...

  3. 转载:关于 WebBrowser只对浏览器外应用程序以及在Internet Explorer 中以提升权限运行的应用程序启用

    我是根据很多大神写的博客,以及我自己在做项目的时候做的关于提升Silverlight 中WebBrowser 提升信任的问题的总结: 1)选中Silverlight主程序,右键“属性”---“Sliv ...

  4. Windows: 在系统启动时运行程序、定时计划任务、定时关机

    lesca今天介绍一些让系统在启动时,而非登录时,加载用户自定义的应用程序或脚本的方法,推荐度从前到后依次递减. 1. Windows任务计划(task scheduler) 用户可以按以下步骤进行操 ...

  5. 简单的java Hadoop MapReduce程序(计算平均成绩)从打包到提交及运行

    [TOC] 简单的java Hadoop MapReduce程序(计算平均成绩)从打包到提交及运行 程序源码 import java.io.IOException; import java.util. ...

  6. 360浏览器兼容模式下IE内核版本

    问题 最近在跟客户演示系统时,自己电脑IE 11下好好的,我们web系统最低支持到IE9.在客户电脑上,IE9浏览器下可以正常浏览,但是360兼容模式下,页面什么也不显示. 通过F12调试工具发现,3 ...

  7. docker学习笔记(6)——docker场景问题汇总(centos7 由于内核版本低带来的一系列问题,docker彻底卸载,安装、启动日志报错分析)

    参考资料: https://nachuan.blog.csdn.net/article/details/96041277 https://www.cnblogs.com/xzkzzz/p/962765 ...

  8. linux系统如何查看内核版本、操作系统版本等信息

    有时候需要查看linux系统的内核版本,可以有多种方法,方法如下:(下面以优麒麟系统为例) 方法1: 打开mate终端,在命令行输入以下命令: uname -a 运行效果如下: ​​​ 如果只查看内核 ...

  9. Ubuntu下查看linux版本,内核版本,系统位数,gcc版本

    1. 查看linux版本  sunny@ubuntu:~$cat /etc/issueUbuntu 11.04 \n \l 2. 查看内核版本1) sunny@ubuntu:~$ cat /proc/ ...

随机推荐

  1. 小技巧:在线生成按钮Shape的网站

    AndroidButton Make  右侧设置按钮的属性,可以即时看到效果,并即时生成对应的.xml 代码,非常高效(当然熟练的话 自己手写代码更快)

  2. websocket 与 tornado 的结合

    对于socket是不陌生的,但是对于websocket我却是陌生的,不同于https,在网页中使用websocket可以同样起到ajax的作用,默默发送数据... 在script中: ws = new ...

  3. git 入门教程之github 教程

    github 教程 github 是一个基于 git 的代码托管平台,是平时工作学习的好帮手,学会如何用好 github 网站能够帮助我们更好分享代码或者与其他开发人员合作. 注册 github 账号 ...

  4. spring4笔记----PropertyOverrideConfigureer 重写占位符配置器(图)

  5. JavaWeb 过滤器——验证登录 防止未登录进入界面

    昨天刚刚完成老师布置的一个Web小项目,项目中用到了两个过滤器(编码过滤.登录过滤) 比如电商网页中有些不需要登录也能访问(首页.商品详细信息...),其他都需要过滤在会话作用域(session)中是 ...

  6. visual studio 启动无法打开IIS express

    删除 解决方案下的vs文件夹之后重新生成

  7. 关于激活Windows10专业版2018长期服务版

    之前重装了一次系统,偷懒用了小白一键重装,装好之后显示的是Windows10专业版2018长期服务版,当时也没想太多就放着用了. 然后 ,这几天一直提示  “你的windows许可证即将过期” ,就按 ...

  8. ELK收集tomcat状态日志

    1.先查看之前的状态日志输出格式:在logs/catalina.out这个文件中 最上面的日志格式我们可能不太习惯使用,所以能输出下面的格式是最好的,当然需要我们自定义日志格式,接下来看看如何修改 2 ...

  9. Caused by: java.io.FileNotFoundException: velocity.log (No such file or directory)

    Caused by: org.apache.velocity.exception.VelocityException: Error initializing log: Failed to initia ...

  10. 轮播图插件swiper 的使用

    引入文件(注:目前版本号为Swiper3.x) <link rel="stylesheet" type="text/css" href="//s ...