根据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);

最新文章

  1. C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解
  2. 【转】WIN32 控制台程序
  3. [转]关于event的两个常被忽略的api:isDefaultPrevented()和preventDefault()
  4. osx 文本编辑工具下载地址Sublime Text 3
  5. 用Navicat for MYsql创建表,插入中文显乱码
  6. [置顶] gridview中嵌套gridview(并实现子gridview的数据绑定),页面传值,加密,数据绑定
  7. MYSQL数据库备份与恢复【转】
  8. 借助bool判断使冒泡排序效率提高
  9. NSString 使用小结
  10. sql执行顺序整理
  11. What is Webhook ( Introduction to Webhook )
  12. Java映射
  13. VLAN的三种类型及三种属性
  14. 云计算OpenStack:云计算介绍及组件安装(一)--技术流ken
  15. 转 mysql Next-Key Locking
  16. 十八、springcloud(四)熔断器
  17. etcd-v2第二集
  18. Linux mmc framework1:软件架构
  19. 关于Java Web应用中的配置部署描述符web.xml
  20. 《全栈性能Jmeter》-6JMeter元件详解

热门文章

  1. vue 获取跳转上一页组件信息
  2. 清幽傲竹实现的kbmMWServer数据库联接失败重联(转载红鱼儿)
  3. 49.UILable宽度高度自适应
  4. 2018.11.01 bzoj4325: NOIP2015 斗地主(贪心+搜索)
  5. (17)Questioning the universe
  6. C++STL deque
  7. SpringBoot2.0.2 不使用parent作为maven单继承方式操作 : org.springframework.boot : spring-boot-dependencies : 2.0.2.RELEASE
  8. SSH 等效性问题 总提示输入密码问题
  9. 1105 Spiral Matrix
  10. (广搜)Fire Game -- FZU -- 2150