Jan 05
Some of the systems that I need to get access to from programs are not available via the web proxy….but others are only available using the web proxy. So I needed a way to turn the proxy on and off depending on which system I needed to connect to. I did some digging around and came up with the following code:
require 'win32/registry'
def proxy_disable
reg = Win32::Registry::HKEY_CURRENT_USER.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\",
Win32::Registry::KEY_WRITE)
reg.write("ProxyEnable", Win32::Registry::REG_DWORD, 0)
end
def proxy_enable
reg = Win32::Registry::HKEY_CURRENT_USER.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\",
Win32::Registry::KEY_WRITE)
reg.write("ProxyEnable", Win32::Registry::REG_DWORD, 1)
end
...
ie = Watir::IE.new
ie.goto("http://website_via_proxy.com/")
proxy_disable()
ie.goto("http://website_direct.com/")
proxy_enable()
You can also modify the proxy server by writing to “ProxyServer”, and change the exceptions list by writing to “ProxyOverride”.







