简体   繁体   中英

Is there a way to create a registry SubKey and set it's value under HKEY_CURRENT_USER\ … \FEATURE_BROWSER_EMULATION\

Is there a way to create a registry SubKey and set it's value under HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION\\ in C#

I've tried

using System.Security.Permissions; 

using Microsoft.Win32;

...

Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\MyApp.exe", true);
Microsoft.Win32.Registry.CurrentUser.SetValue(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\MyApp.exe", 11001);

but it creates the registry SubKey under HKEY_CURRENT_USER

I want to set the version of Internet Explorer used by the WPF WebBrowser Control and don't really know how to

You should check your key exists and if not create it

 var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);
        var key = localMachine.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);

        var subKey = key.OpenSubKey("MyApp.exe", true);
        if (subKey == null)
        {
            subKey = key.CreateSubKey("MyApp.exe");                 
        }

        subKey.SetValue("MyApp.exe", 10001);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM