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)
Related
This is related to my other recent question on Selenium (that question was about a Firefox-specific issue, this one is about an IE-specific issue).
Basically, when I ran the following code
ieDriver.Navigate().GoToUrl("http://localhost:51282");
IWebElement linkToAboutPage = ieDriver.FindElement(By.Id("test"));
linkToAboutPage.Click();
to simulate clicking on a link, it successfully navigates to the page but when it tries to retrieve the actual element I get the following exception:
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to find element on closed window
The accepted answer to this question suggests that "Enable Protected Mode" in IE Security Settings should either be all selected or all unselected. Indeed, when I look at these settings, "Enable Protected Mode" is unselected for Intranet but not for the others:
Unfortunately, as the screenshot shows, that's being managed by my corporate IT department and I'm not sure that I'll have much luck convincing them to let me change the settings. I was also unable to edit my registry in the way suggested by some of the other answers (presumably due to the lack of administrative rights).
Some of the other solutions I've seen include setting IntroduceInstabilityByIgnoringProtectedModeSettings to true, providing a InitialBrowserUrl, or setting EnsureCleanSession to true. As shown below, I'm currently doing all of those things:
var ieOptions = new InternetExplorerOptions()
{
InitialBrowserUrl = "http://www.google.com",
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
IgnoreZoomLevel = true,
EnableNativeEvents = true,
EnsureCleanSession = true
};
ieDriver = new InternetExplorerDriver(ieOptions);
ieDriver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 10);
However, I'm still having the exact same problem.
Is there something else I can try that doesn't involve me bugging corporate IT for policy exceptions?
Perhaps significantly, this only happens when I'm running on localhost (which is a problem because that's where I intend to do most of my testing).
I found that setting the InitialBrowserUrl capability to the starting URL you want to navigate to, paired with IntroduceInstabilityByIgnoringProtectedModeSettings = true, works for me.
var ieOptions = new InternetExplorerOptions()
{
InitialBrowserUrl = <your-starting-url>
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
...
};
Unfortunately I don't have a reason as to why this works, so this "fix" might simply be anecdotal...
Here's some other solutions you can try (from the official reference):
Required Configuration
The IEDriverServer exectuable must be downloaded and placed in your PATH.
On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.
Reference:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
I noticed that when I start up IE in SeleniumWebdriver with
var ieoptions = new InternetExplorerOptions()
{
EnablePersistentHover = false,
EnsureCleanSession = true,
RequireWindowFocus = true,
};
I have this -noframemerging flag in my IE command line. I don't want this flag
After some digging I managed to find that I can seemingly take it out by adding
ForceCreateProcessApi = true,
BrowserCommandLineArguments = "-framemerging"
but that would only work with an accompanying regedit for
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main = 0
I'd prefer to keep my IE working in the same way in manual and automated tests - i.e. not messing about with the number of processes in play. So is there an easier solution available here? I find it hard to understand why the -noframemerging flag is turned on by IEServerDriver
No, there is no easier solution here. IEDriverServer.exe does nothing to modify the command line used to launch IE. If a switch is being added to the command line, it's being done by the Windows IELaunchURL API, which is what the driver uses by default to launch the browser to be able to accommodate Protected Mode. The way to have "control" over what command line is used is with the CreateProcessAPI, and you've already discovered how to make the driver do that. "Control" is deliberately put in scare quotes here because unfortunately, CreateProcess isn't reliable with IE unless you use the registry entry. Moreover, IE doesn't have the concept of user profiles, and your desire to maintain the browser's behavior for your non-WebDriver use is exactly why the driver doesn't set registry entries for you.
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.
I am trying to change some windows settings by group policy settings using C#.
My application creates sub-keys in the group policy objects section successfully,
But some times they doesn't work.
For example i am trying to disable desktop using Group policy, I take these steps :
I run Process monitor and configure it to show me the registry changes relating to mmc.exe
Then run gpedit.msc and navigate to the desired option and change it
I copy the registry change which is shown in Process monitor and use it
in my app like this :
mmc.exe RegSetValue HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{FD0F8A58-1909-410F-8860-4CFF7766FA89}User\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDesktop SUCCESS Type: REG_DWORD, Length: 4, Data: 1
And use it like this :
string regPath = #"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer";
string option = "NoDesktop";
SetGroupPolicySetting(regPath, option, 1);
SetGroupPolicySetting uses a dll which can be downloaded from here and is written like this :
private void SetGroupPolicySetting(string registryKeyPath,
string option,
int value ,
GroupPolicySection groupPolicySection = GroupPolicySection.User)
{
var gpo = new ComputerGroupPolicyObject();
RegistryKey registryKey = gpo.GetRootRegistryKey(groupPolicySection);
registryKey.CreateSubKey(registryKeyPath).SetValue(option, value , RegistryValueKind.DWord);
gpo.Save();
}
After that , there are two subkeys created which are:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}Machine
and
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}User
and finally the NoDesktop option in Explorer section is created in this address :
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}User\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
though still its not working ! Whats wrong ? its driving me insane!
Setting a GPO alone does not make it active. GPOs usually get reapplied at boot or after a certain period of time. You can probably run something like gpupdate /force (as Administrator) to force reapplying GPOs.
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.