Last active
August 20, 2019 22:41
-
-
Save jjeffery/b2fe7a0ebd34f152d30e33a287fe0881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Windows.Forms; | |
using Microsoft.Win32; | |
namespace Example | |
{ | |
static class IE | |
{ | |
private const string FeatureControlKey = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl"; | |
/// <summary> | |
/// Update the Windows Registry to configure the WebBrowser control to run the latest version | |
/// of IE for the currently executing program. | |
/// </summary> | |
public static void UpdateRegistry() | |
{ | |
var currentUserKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); | |
var valueName = Path.GetFileName(Application.ExecutablePath); | |
RegistryKey regKey = null; | |
try | |
{ | |
// Registry setting to run IE11 mode. | |
const string keyName = FeatureControlKey + @"\FEATURE_BROWSER_EMULATION"; | |
regKey = currentUserKey.CreateSubKey(keyName); | |
regKey?.SetValue(valueName, 0x2af9, RegistryValueKind.DWord); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
finally | |
{ | |
regKey?.Close(); | |
regKey = null; | |
} | |
try | |
{ | |
// Registry setting for correct operation on high DPI monitors | |
const string keyName = FeatureControlKey + @"\FEATURE_96DPI_PIXEL"; | |
regKey = currentUserKey.CreateSubKey(keyName); | |
regKey?.SetValue(valueName, 1, RegistryValueKind.DWord); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
finally | |
{ | |
regKey?.Close(); | |
currentUserKey.Close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment