Responding to search-strings (II)

While looking through the logfile analysis of I saw that someone came to this site searching with

set ie proxy delphi

so I deceided that it’s time for anther episode of “Responding to search-strings” (the other being here). This time it’s about setting the IE’s proxy server from a delphi application.

When you do it manually, you access the proxy server settings from Tools / Internet Options / Connections in Internet Explorer. Whatever you change there, is used not only by IE, but by every application on your system using the WinInet API function InternetOpen with the flag INTERNET_OPEN_TYPE_PRECONFIG set. Additionally, many applications use the WinInet-API to get the Proxy Server settings and then use their own routines to actually connect to the server via the proxy they got before

So, if you want to change the Internet Explorer Proxy settings, you actually change it for the bigger part of the wohle system

When you go to Tools / Internet Options / Connections, you will immediately see that setting the proxy is going to be quite a task: You don’t just set one proxy server, you actually set one for LAN-Connections and one for each dialup connection that is installed on your system. Finally the proxy being used depends on the state of the radio buttons you see in the middle of the dialog because they define whether IE should even bother connecting to the LAN or just call one of the connections defined.

But it gets even more complicated: The proxy settings provided changed for each version of Internet Explorer. As always, it was an evolutionary process getting more complex in every iteration, so you will have to cope with that too.

But now to the details: While the settings are stored in the Registry, this is not the recommended way for changing them. Microsoft has created some API functions specifically for that, so you should use them as this is the only way guaranteed to be portable even for future versions of Windows.

The problem: The API is very painful to use – even more so because it is somewhat different for each version of IE (getting more complex along the proxy feature itself). Oh, and please don’t ask me how to get the version of the installed IE – that I do not know.

All is about InternetSetOption and InternetQueryOption respectivly. Both require a parameter to tell them which option you are interested in. Have a look at INTERNET_OPTION_PER_CONNECTION_OPTION (for IE5 and later), INTERNET_OPTION_PROXY and INTERNET_PER_CONN_OPTION

In the end, you will be calling InternetQueryOption quite a lot of times and change some settings with InternetSetOption, but you will soon see that it’s not actually worth it: There is always the possiblity that you have not anticipated some obscure setting a user may have which will distrub your application greatly

And additionally, changing the proxy server settings is a task for an adminitrator, not for a simple application. Before asking the question “How can I change the proxy server?”, the question should be “Do I really have to change the proxy server? Isn’t there a better way?”

%d bloggers like this: