• 在.net中修改Webbrowser控件的IE版本


    根据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 = @"SOFTWAREWOW6432NodeMicrosoftInternet ExplorerMAINFeatureControlFEATURE_BROWSER_EMULATION";
                }
                else
                {
                    regPath = @"SOFTWAREMicrosoftInternet ExplorerMAINFeatureControlFEATURE_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);
    
  • 相关阅读:
    selenium webdriver 执行Javascript
    selenium webdriver 定位元素 第一部分
    selenium webdriver 模拟鼠标悬浮
    JaveWeb 公司项目(3)----- 通过Thrift端口获取数据库数据
    JaveWeb 公司项目(2)----- 类模态窗口显示DIV并将DIV放置在屏幕正中间
    JaveWeb 公司项目(1)----- 使Div覆盖另一个Div完成切换效果
    Intellij Idea修改css文件即时更新生成效果
    Intellij idea 2017 图标含义
    下载安装tomcat和jdk,配置运行环境,与Intellij idea 2017关联
    IntelliJ IDEA Tomcat中端口被占用的问题
  • 原文地址:https://www.cnblogs.com/yczz/p/4434865.html
Copyright © 2020-2023  润新知