I want to force the webbrowser to use IE10 in my c# winform application.
I know there are other questions like this but i've already read a lot of them and i don't know where i'm wrong.
This is my code:
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
registrybrowser.SetValue("myAppName", 0x02710, RegistryValueKind.DWord); //Even with QWord
I've tried different ways to set the value like:
registrybrowser.SetValue("myAppName", 1000, RegistryValueKind.DWord); //Even with QWord and String
registrybrowser.SetValue("myAppName", 1000); //even with 0x02710
I write it in the costructor of my main project before InitializeComponent().
I've got Admin permission set in the .manifest file
Thanks to all, BlackShawarna
EDIT: I discovered that the RegistryKey.SetValue(...); created a key in another path:
(#"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION")
even if my instruction said: Registry.LocalMachine.OpenSubKey
(#"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
I think it happens because IE10 works on 32bit mode. However I don't understand why it writes in that path even if i specified another one and, above all, why my application doesn't work even if I open Registry.LocalMachine.OpenSubKey(#"Software\Wow6432Node....");
If I run my program only in x64 mode, going to properties/build/x64, it won't write the key in my original path.
I had the same problem that my app wrote the value to "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION".
I changed LocalMachine to CurrentUser and now it works.
string executablePath = Environment.GetCommandLineArgs()[0];
string executableName = System.IO.Path.GetFileName(executablePath);
RegistryKey registrybrowser = Registry.CurrentUser.OpenSubKey
(#"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
if (registrybrowser == null)
{
RegistryKey registryFolder = Registry.CurrentUser.OpenSubKey
(#"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl", true);
registrybrowser = registryFolder.CreateSubKey("FEATURE_BROWSER_EMULATION");
}
registrybrowser.SetValue(executableName, 0x02710, RegistryValueKind.DWord);
registrybrowser.Close();
The executableName is something like "myAppName.exe"
Note: If the WebBrowser Controls inside a DLL you need to specify the hosting EXE's name whatever that might be, eg System.AppDomain.CurrentDomain.FriendlyName
FEATURE_BROWSER_EMULATION "myAppName.exe"=10000 (or 0x02710) and not 1000.
In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
and HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
It works for me
You've got to say 'myAppName.exe' not 'myAppName'
If you have control over the page being rendered (a intranet page for instance) and also of the application that renders the page using the WebBrowser control, you can specify a meta tag in the page
<meta http-equiv="X-UA-Compatible" content="IE=10" />
and make use of the WebBrowser control as needed. You must have IE 10 on the machine.
Just in case you want to emulate other versions of IE, you could simply replace "IE=10" with "IE=EmulateIE9", "IE=EmulateIE8" etc.
Related
So the title says it all, I would like C# code (so please, PLEASE make sure it isn't Visual Basic code). And that is all I want to ask. I have tried the web browser built in to the .NET framework, but it looks like some old version of IE (if I am right or not). And if you answered, well thanks I guess! I need this for a small project where a bot would just log on to a website (its a base for future projects).
By default it's IE7. You can bang a registry entry in to make it later:
public static void EnsureBrowserEmulationEnabled(string exename = "YourAppName.exe", bool uninstall = false)
{
try
{
using (
var rk = Registry.CurrentUser.OpenSubKey(
#"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true)
)
{
if (!uninstall)
{
dynamic value = rk.GetValue(exename);
if (value == null)
rk.SetValue(exename, (uint)11001, RegistryValueKind.DWord);
}
else
rk.DeleteValue(exename);
}
}
catch
{
}
}
Code courtesy of this blog
The values you can use in place of 11001 can be found in MSDN
Alternatively; can you do what you want by using WebClient/HttpWebRequest rather than poking at a web browser control to navigate around? Or can you find some web service/api version of the site that will respond with JSON rather than trying to manipulate html?
I was mildly curious why you'd care what a page looks like if it's a bot that is using it, but perhaps you're hitting a "your IE is too old" from the server..
I have created an application(windows) compiled with .NET 4.6.1 and used the FolderBrowserDialog object. When a button is pressed I execute this code:
FolderBrowserDialog folderbrowserdialog = new FolderBrowserDialog();
folderbrowserdialog.Description = "Custom Description";
if (folderbrowserdialog.ShowDialog() == DialogResult.OK)
{
filePath = folderbrowserdialog.SelectedPath ;
}
what i get from the folderbrowserdialog(like foto)
however ,the folder browserdialog is not showing the networks shared folder(that the purpose of my app) otherewise just the pc folders.
but what i want to get it is the network shared folders which could i also access from windows 10 like foto here:
notes to be marked:
i could not use the open file dialog cause i need the folder location.
i desgined the Appto be opened just like admin by adding manisfest so the app is always starting like admin.
the app should be comptiable with windows 10,7
note i know that i could try setting this registry option (could be broken in Win10):
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System
EnableLinkedConnections=1
but it does not make a sense to add this registry by every customer PC
so is there any tipps to show the network shared folders in FolderBrowserDialog ?
Finally after reading many topics i found that the only solution is to add a Registry key programmatically so here how to add specfic C# Registry Subkey with dword value:
i wrote a method wich could all use it
just to let you know after using it you have to restart the device after it ,it will work ;)
public void ConfigureWindowsRegistry()
{
RegistryKey localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64); //here you specify where exactly you want your entry
var reg = localMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
if (reg == null)
{
reg = localMachine.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
}
if (reg.GetValue("EnableLinkedConnections") == null)
{
reg.SetValue("EnableLinkedConnections", "1", RegistryValueKind.DWord);
MessageBox.Show(
"Your configuration is now created,you have to restart your device to let app work perfektly");
}
}
I had the same issue. The reason of the problem: I was using as an Administrator. The mapped drives are related to the user, so I tried to use as an normal user and I could see the mapped drives.
I'm trying to disable Internet Explorer 11 AutoComplete for usernames and passwords on forms using the Windows Registry in a c# application.
The following code works some times (browser stops asking to save passwords and the checkboxes in AutoComplete Settings is unchecked), and fails at other times (that is, no exceptions but the browser still asks if you want to save passwords, and the checkboxes in AutoComplete settings are checked).
My question:
Is there another key that controls password saving, or is it perhaps failing due to the user's privileges? Or am I assigning the wrong value to the subkeys? Why would it work sometimes and fail silently others?
Another question: If a website is running in compatibility view, which displays webpages as if they were viewed by an earlier version of the browser, does IE11 then use the registry keys from the older versions (eg, HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\AutoComplete?)
// Keys I am manipulating:
// HKCU\Software\Microsoft\Internet Explorer\Main\FormSuggest Passwords
// HKCU\Software\Microsoft\Internet Explorer\Main\FormSuggest PW Ask
// others?
RegistryKey regKey1 = default(RegistryKey);
regKey1 = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Internet Explorer\Main", true);
regKey1.SetValue("FormSuggest Passwords", "no", RegistryValueKind.String);
regKey1.Close(); //are these values ok?
RegistryKey regKey2 = default(RegistryKey);
regKey2 = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Internet Explorer\Main", true);
regKey2.SetValue("FormSuggest PW Ask", "no", RegistryValueKind.String);
regKey2.Close();
Edit:
I have since discovered several other registry items that appear related to Auto Complete, but it is unclear which version of Internet Explorer these apply to. It also seems very difficult to find information about IE 11 registry settings in general.
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\AutoComplete
HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Control Panel\FormSuggest
HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Control Panel\FormSuggest Password
Setting access control for the registry key might help to resolve your problem
example
string user = Environment.UserDomainName + "\\" + Environment.UserName;
RegistrySecurity regSecurity = new RegistrySecurity();
rs.AddAccessRule(new RegistryAccessRule(user,
RegistryRights.ReadKey | RegistryRights.WriteKey,
InheritanceFlags.None,
PropagationFlags.None,
AccessControlType.Allow));
RegistryKey regKey1 = null;
try
{
regKey1 = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Internet Explorer\Main",
RegistryKeyPermissionCheck.Default, rs);
regKey1.SetValue("FormSuggest Passwords", "no",RegistryValueKind.String);
}
catch (Exception ex)
{
Console.WriteLine("\r\nUnable to read key: {0}", ex);
}
These keys are also accessed by Internet Explorer when internet options->autocomplete is loaded:
HKCU\Software\Microsoft\Internet Explorer\DomainSuggestion\Enabled
HKLM\Software\Microsoft\Internet Explorer\DomainSuggestion
HKCU\Software\Microsoft\Internet Explorer\Main\Use FormSuggest
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoComplete
HKCU\Software\Policies\Microsoft\Windows\CurrentVersion\Explorer\AutoComplete
Seems windows explorer and internet explorer share some autocomplete options.
You can use some registry monitoring tools to see what is being accessed in compatibility view. This is how I found these keys.
So, I have a task to:
1. Delete all settings in Internet Connection Properties
2. Set Use Automatic Configuration Script to my script
This is my code, and sometimes it works and values are in IE, and sometimes values are not in IE. I am frustrated with this hectic behavior and wondering where is my error (not in DNA ;))
RegistryKey registry = Registry.CurrentUser.OpenSubKey(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", 0);
registry.Close();
RegistryKey registry2 = Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true);
registry2.DeleteValue("DefaultConnectionSettings", false);
registry2.Close();
RegistryKey registry3 = Registry.CurrentUser.OpenSubKey(
#"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
registry3.SetValue("AutoConfigURL", #"http://wwwwwwwww/configscript.pac", Microsoft.Win32.RegistryValueKind.String);
registry3.SetValue("ProxyEnable", 000000, RegistryValueKind.DWord);
registry3.Close();
I suspect that the issue you face has something to with stale values on the UI.
The quickest way to check whether your settings are "sticky" is to open Internet options and going to Lan settings directly from control panel.
The following command will launch "internet options"
control inetcpl.cpl
Further if your machine belongs to some corporate domains, there might be group policies set by admins that periodically enforces some values for these parameters.
In such cases, you might have to schedule a task for say every 10 minutes, and enforce values of your choice. (note: that is what I have been doing for quite some time)
I'm trying to open a url in the default browser. Obviously I thought that Shell Exec will open it in the default browser but it doesn't.
Then I tried explicit:
Process.Start(GetDefaultBrowserPath(), "http://stackoverflow.com");
private static string GetDefaultBrowserPath()
{
string key = #"htmlfile\shell\open\command";
RegistryKey registryKey =
Registry.ClassesRoot.OpenSubKey(key, false);
// get default browser path
return ((string)registryKey.GetValue(null, null)).Split('"')[1];
}
It always returns Internet Explorer but not my default which is Firefox. I tried it on several computers...
I don't care which way to call the link in the default browser, but it has to be the default
Have you tried just running:
Process.Start("http://stackoverflow.com");
My test application (below) opens the site in my default browser:
using System;
using System.Diagnostics;
namespace ProcessStartSample
{
class Program
{
static void Main(string[] args)
{
Process.Start("http://stackoverflow.com");
}
}
}
In other words, let the operating system do the heavy work of working out what the users default browser is for you! =)
Just Try this :)
Process.Start("http://stackoverflow.com");
And if you want to find your default browser you should open HKEY_CLASSES_ROOT\http\shell\open\command\default key.
Please pay attention "http" not "htmlFile"
EDIT:
CODE:
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(#"http\shell\open\command", false);
string value = registryKey.GetValue("").ToString();
Windows will start the default browser on the user's system for you automatically if you just specify the URL to open:
Process.Start("http://www.google.com/");
No need for any fancy Registry trickery, unless you are trying to ascertain which browser is set as the default.