Question

I'm using this code to allow browser feature emulation in my wpf application :

string executablePath = Environment.GetCommandLineArgs()[0];
MessageBox.Show(executablePath);
string executableName = System.IO.Path.GetFileName(executablePath);
MessageBox.Show(executableName);

MessageBox.Show("Is64BitOperatingSystem : " + Environment.Is64BitOperatingSystem);

string key = string.Empty;
if (Environment.Is64BitOperatingSystem)
    key = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
else
    key = @"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";

RegistryKey registrybrowser = Registry.CurrentUser.OpenSubKey(key, true);
MessageBox.Show(registrybrowser.ToString());

if (registrybrowser == null)
{
    RegistryKey registryFolder = Registry.CurrentUser.OpenSubKey
        (@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl", true);
    MessageBox.Show(registryFolder.ToString());
    registrybrowser = registryFolder.CreateSubKey("FEATURE_BROWSER_EMULATION");
}
registrybrowser.SetValue(executableName, 0x02710, RegistryValueKind.DWord);
registrybrowser.Close();

When I try to run my application on Windows XP (SP2, FW 4), the registrybrowser object is null because the key is not found I guess. How can I set this feature emulation on Windows XP ?

No correct solution

OTHER TIPS

I did not have the FeatureControl registry key on my Windows XP. Here is how to fix it :

string executablePath = Environment.GetCommandLineArgs()[0];
string executableName = System.IO.Path.GetFileName(executablePath);

string key = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";

RegistryKey registrybrowser = Registry.CurrentUser.OpenSubKey(key, true);

if (registrybrowser == null)
{
    RegistryKey registryFolder = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl", true);

    if (registryFolder == null)
    {
        RegistryKey registryFolderParent = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main", true);
        registryFolderParent.CreateSubKey("FeatureControl");
        registryFolder = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl", true);
    }

    registrybrowser = registryFolder.CreateSubKey("FEATURE_BROWSER_EMULATION");
}
registrybrowser.SetValue(executableName, 0x2AF9, RegistryValueKind.DWord);
registrybrowser.Close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top