views:

207

answers:

1

This is the code that I use to enable the proxy. It has worked fine on all versions of windows up until Server 2008 R2 (Windows 7 Kernal). Now it only works the fist time. I start my application and enable the proxy and that works fine. I then try disabling it using code similar to the code below. It never gets disabled. If I manually disable it by going into internet options and then try enabling it again via my application, it doesn't get enabled.

From what I can tell, the first InternetSetOption command in my code is reverting the changes I make with the regKey.SetValue() function. At least that is what appears to be happening when I step through it. Has anyone seen this problem before, or knows how to fix it. I have been trying to find a work around for awhile now and nothing has turned up. Any input will be appreciated.

regKey.SetValue("ProxyServer", "localhost:" + Settings.Default.Port, RegistryValueKind.String);
regKey.SetValue("ProxyEnable", 1, RegistryValueKind.DWord);
         regKey.Flush();
InternetSetOption(IntPtr.Zero, 39, IntPtr.Zero, 0); //INTERNET_OPTION_SETTINGS_CHANGED
InternetSetOption(IntPtr.Zero, 37, IntPtr.Zero, 0); //INTERNET_OPTION_REFRESH
A: 

Enabling and disabling the proxy by writing to the registry is not really a good practice. See this question:

http://stackoverflow.com/questions/1393713/enabling-disabling-proxy-app-doesnt-work-properly-with-ie

MusiGenesis