Monday, January 26, 2009

because not everybody will use transparent proxies.

As I travel around and attach my laptop to different networks, I'm left to disable/enable the proxy server settings ever so often. I grew tired of it and that's why I messed around with a small vbscript that :
a) detects whether the proxy settings are enabled or disabled
b) asks you to reverse that state

you may want to add additional code to enable disable different proxies.

Here's the code :
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer &"\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
strValueName = "ProxYEnable"

oReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If dwValue = 1 Then
answer=Msgbox("Proxy is currently enabled. Disable it?",36)
ProxyOn = True
Elseif dwValue = 0 Then
answer=Msgbox("Proxy is currently disabled, Enable it?",36)
ProxyOn = False
End if

If ProxyOn=False Then
If answer = 6 Then
dwValue = 1
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
Elseif answer = 7 Then
dwValue = 0
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
End if
Elseif ProxyOn=True Then
If answer = 6 Then
dwValue = 0
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
Elseif answer = 7 Then
dwValue = 1
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
End if
End If

Have fun!
Stay Secure!

No comments: