Take the 2-minute tour ×

I'm using WinHttpGetIEProxyConfigForCurrentUser and friends to gather the current proxy information when my app starts as doing it before each request seems to degrade performance greatly with it something sitting for a few seconds gathering the proxy data. Is there a way to detect when the Windows proxy settings have changed so I can cache the information until it changes?

Thanks, J

share|improve this question
There's no supported API to detect proxy setting changes in WinINET; the code internally sets a flag in the shared memory cache database which all WinINET clients pick up on subsequent requests, but there's no notification surfaced for other clients. Watching the registry key as Luke suggests will work for some scenarios (e.g. LAN proxy) but not others (e.g. VPN attach/detach). The delay you're seeing is probably occurring when the user has "AutoDetect" selected and the WPAD algorithm gets run in your code. –  EricLaw Jun 1 '11 at 3:27

3 Answers 3

up vote 1 down vote accepted

Not sure if there is a better way, but you could always take the nuclear option and use RegNotifyChangeKeyValue with HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings.

share|improve this answer
Incidentally, this appears to be basically what Firefox is doing; they read the ProxyServer registry key again for every single HTTP request they make. (Scary!) –  EricLaw Jun 1 '11 at 3:54
This is actually what I've been leaning towards, seems a bit "wrong" but if the "right" way of doing it slows down your application what choice do we have? –  JWood Jun 1 '11 at 9:24

Could you run the detection in a background thread upon application startup?

I found nothing about WinHttpGetIEProxyConfigForCurrentUser not being callable from within the non-main-UI thread.

If the application needs the result of the WinHttpGetIEProxyConfigForCurrentUser faster than the background thread returns, you could make it blocking again until the background thread is finished.

share|improve this answer
Thanks for the suggestion but the app makes a large number of individual requests and querying the proxy data before each request results in a delay. I suppose I could periodically update the proxy information rather than cache it for the life of the application but applications like Firefox etc pick up the proxy change instantly so there must be a way to detect it or load it quicker. –  JWood May 31 '11 at 19:43
@JWood Personally, I would ignore the fact, that the proxy changes when my application runs; I would put it on the user to manually restart my application if he intends to change the proxy. So I would once read in the proxy information at the application startup and keep it the entire lifetime. –  Uwe Keim May 31 '11 at 19:47
That's actually what I'm doing now but I thought it would be handy (mostly for me loading up Fiddler) to have it auto-detect. Partly my own laziness motivating me here! –  JWood May 31 '11 at 19:50
@JWood You could add a button to your application for this purpose or pass a polling interval ("Every 10 seconds") to your application via command line or configuration file. –  Uwe Keim May 31 '11 at 20:00

I'm not sure if it is generated with proxy setting changes or not, but there might be a WM_SETTINGCHANGE message that you could handle.

share|improve this answer

Your Answer


