WrijuB
WrijuB

Reputation: 141

Setting IE proxy values using VBscript

I've written a small piece of vb script to set the proxy settings


'begin script
Option Explicit
Dim valUserIn
Dim objShell, RegLocate
Set objShell = WScript.CreateObject("WScript.Shell")
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"0","REG_DWORD"
WScript.Sleep(5000)
valUserIn = Inputbox("Enter the Proxy server you want to use.","Proxy Server Required","proxygate.mydomain.com:8080")
if valUserIn = "" then
    RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
    objShell.RegWrite RegLocate,"0","REG_DWORD"
    'MsgBox "No proxy mode"
else
    RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
    objShell.RegWrite RegLocate,valUserIn,"REG_SZ"
    RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
    objShell.RegWrite RegLocate,"1","REG_DWORD"
    'MsgBox "Proxy mode: " & valUserIn
end if
WScript.Quit
'end script

Now the script runs properly and it is able to set the registry value. If I use Internet Explorer there are no issues i.e. the browser uses the correct proxy settings (as entered in the input dialog or 'no proxy' if cancelled) server.

However when Firefox or Chrome are used (tried with different versions) when the browser behaves oddly. Sometimes the correct proxy server is used however at times the browser displays a message the proxy server is refusing connections (basically it was not able to reach the proxy server). Moreover this behavior is random, it is not based on idle time of the browser or the number of requests/clicks.

One more analysis which I have done is, whenever this happens if I open up internet explorer's options dialog and click on LAN settings (where the proxy can be changed) I notice that the proxy settings are set properly. If I simply click on Cancel and exit the dialog the browsers start using the correct settings.

Any tips on what Internet explorer does and how we can automate that in the script????

Thanks and Regards

Upvotes: 2

Views: 23293

Answers (1)

anishsane
anishsane

Reputation: 20980

different browsers store proxy information at different places.

  1. IE stores it in registry.
  2. firefox stores it in (some file in) %appdata%\mozilla\firefox\profiles\
  3. chrome also uses same place as IE, AFAIK.

However, there may be an option in other browsers, where we can ask it to use system level proxy (set in IE). The linux version of FF has this.
Even with this, you would need to restart the browser, so that it will read the proxy server value again. Normally it is read at startup & is updated only manually, using dialog boxes. Browser programmers normally do not expect users to change proxy using script. (We however, do it :-) )

Upvotes: 1

Related Questions