根据32位、64位系统来分别修改对应的注册表路径的键值对,不需要重启程序。


/// <summary>
/// 修改Webbrowser控件模拟的IE版本
/// </summary>
/// <param name="ieMode">
/// 7000: Pages containing standards-based <!DOCTYPE> directives aredisplayed in IE7 mode.
/// 8000: Pages containing standards-based <!DOCTYPE> directives aredisplayed in IE8 mode
/// 8888: Pages are always displayed in IE8mode, regardless of the <!DOCTYPE>directive. (This bypasses the exceptions listed earlier.)
/// 9000: Use IE9 settings!
/// 9999: Force IE9
/// 10000: Use IE10 settings
/// 11000: Use IE11 settings
/// </param>
public static void ChangeWebbrowserMode(int ieMode)
{
string appName = AppDomain.CurrentDomain.FriendlyName;
string regPath = "";
if (Is64BitOperatingSystem())
{
regPath = @"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
}
else
{
regPath = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
}
using (RegistryKey ieMainKey = Registry.LocalMachine.OpenSubKey(
regPath, true))
{
var orignalMode = ieMainKey.GetValue(appName);
if (orignalMode == null || (int)orignalMode != ieMode)
{
ieMainKey.SetValue(appName, ieMode, RegistryValueKind.DWord);
}
//
}
} /// <summary>
/// The function determines whether the current operating system is a
/// 64-bit operating system.
/// </summary>
/// <returns>
/// The function returns true if the operating system is 64-bit;
/// otherwise, it returns false.
/// </returns>
public static bool Is64BitOperatingSystem()
{
if (IntPtr.Size == 8) // 64-bit programs run only on Win64
{
return true;
}
else // 32-bit programs run on both 32-bit and 64-bit Windows
{
// Detect whether the current process is a 32-bit process
// running on a 64-bit system.
bool flag;
return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") &&
IsWow64Process(GetCurrentProcess(), out flag)) && flag);
}
} /// <summary>
/// The function determins whether a method exists in the export
/// table of a certain module.
/// </summary>
/// <param name="moduleName">The name of the module</param>
/// <param name="methodName">The name of the method</param>
/// <returns>
/// The function returns true if the method specified by methodName
/// exists in the export table of the module specified by moduleName.
/// </returns>
static bool DoesWin32MethodExist(string moduleName, string methodName)
{
IntPtr moduleHandle = GetModuleHandle(moduleName);
if (moduleHandle == IntPtr.Zero)
{
return false;
}
return (GetProcAddress(moduleHandle, methodName) != IntPtr.Zero);
} [DllImport("kernel32.dll")]
static extern IntPtr GetCurrentProcess(); [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr GetModuleHandle(string moduleName); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr GetProcAddress(IntPtr hModule,
[MarshalAs(UnmanagedType.LPStr)]string procName); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);

在.net中修改Webbrowser控件的IE版本的更多相关文章

  1. Winform中修改WebBrowser控件User-Agent的方法(已经测试成功)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  2. C#中实现WebBrowser控件的HTML源代码读写

    原文:C#中实现WebBrowser控件的HTML源代码读写 C#中实现WebBrowser控件的HTML源代码读写http://www.blogcn.com/user8/flier_lu/index ...

  3. vs2005中的WebBrowser控件的简单应用

    原文:vs2005中的WebBrowser控件的简单应用 这个控件被封装了一下,和以前的调用方式稍有不同.事件还是那几个,变化不大.方法变了不少.从网上能查到的资料不多,贴出一些代码来作参考.看看这段 ...

  4. WPF中嵌入WinForm中的webbrowser控件

    原文:WPF中嵌入WinForm中的webbrowser控件 使用VS2008创建WPF应用程序,需使用webbrowser.从工具箱中添加WPF组件中的webbrowser发现其中有很多属性事件不能 ...

  5. 在VC中使用WebBrowser控件的两方法

    ClassWizard方式: 1.创建包装类:View->ClassWizard->Add Class->Form a Type Library->C:/winnt/syste ...

  6. 强制IE浏览器或WebBrowser控件使用指定版本显示网页

    自从装了IE10之后,就发现好些个网站显示都不是那么的正常,网站上有些功能竟然还会出现一些意想不到的BUG——本来就是针对IE开发的,现在IE下竟然用不起来了,让用户情何以堪?但是就为少量用户使用的系 ...

  7. [JavaScript]WebBrowser控件下IE版本的检测

    转载请注明原文地址:https://www.cnblogs.com/litou/p/10772272.htm 在客户端检查用户使用的浏览器类型和版本,都是根据navigator.userAgent属性 ...

  8. 修改WebBrowser控件的内核解决方案

    方法一 加入你想让WebBrowser控件的渲染模式编程IE8的标准模式, 你可以通过设置注册表FEATURE_BROWSER_EMULATION 来实现. 示例: 注册表中注明当前本机装的IE版本H ...

  9. C#中的WebBrowser控件的使用

    0.常用方法   Navigate(string urlString):浏览urlString表示的网址 Navigate(System.Uri url):浏览url表示的网址 Navigate(st ...

随机推荐

  1. 设置frameset高度

      设置frameset的高度 设置frameset高度 目前做了一个项目,界面如下: 这是使用frameset做的,在宽屏下开发一直没有发现什么问题,直到一个用户使用800*600的机子测试的时候, ...

  2. JS closure

    闭包的概念 闭包,不同于一般的函数,它允许一个函数在立即词法作用域外调用时,仍可访问非本地变量. --维基百科 闭包就是能够读取其他函数内部变量的函数. --阮一峰 由于在Javascript语言中, ...

  3. spring学习 十三 注解AOP

    spring 不会自动去寻找注解,必须告诉 spring 哪些包下的类中可能有注解,也就是要开启注解扫描,注解的包是spring-context.jar,所以在配置文件中还要引入context约束,也 ...

  4. Android Camera后台拍照

    http://item.congci.com/item/android-camera-houtai-paizhao 有许多人希望在不让用户知道的情况下,使用Android后台Service调用摄像头拍 ...

  5. 33、iOS10 由于权限问题导致崩溃的大坑

    控制台报忠告: This app has crashed because it attempted to access privacy-sensitive data without a usage d ...

  6. [转]order by 与索引

    ORDER BY 通常会有两种实现方法,一个是利用有序索引自动实现,也就是说利用有序索引的有序性就不再另做排序操作了.另一个是把结果选好之后再排序. 用有序索引这种,当然是最快的,不过有一些限制条件, ...

  7. (9)How to take a picture of a black hole

    https://www.ted.com/talks/katie_bouman_what_does_a_black_hole_look_like/transcript 00:13In the movie ...

  8. boost-断言

    标准assert宏的原型声明在<assert.h>中,其作用是如果它的测试条件为假,则调用abort()终止程序执行,程序退出的时候会弹出一个错误提示框,并向控制台输出所在文件及行号.as ...

  9. bootstrap 后台模板

    http://wangye0119-html1.demo.smallseashell.com/index.html

  10. 第08章:MongoDB-CRUD操作--文档--删除

    ①语法 remove()  [2.6以后方法过时] deleteOne() [2.6以后官方推荐] deleteMany() [2.6以后官方推荐] db.collection.remove( < ...