'*******************
'Author: Kingzl3y
'Name: Proxy tool
'Description: Enable/Disable and edit proxy address
'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
'Have fun
'Website - Coming soon.
'*******************
Option Explicit 'ALWAYS !!!!!!!
Dim AllowEvents As Boolean ' Define AllowEvens as boolean
Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
Private Sub Form_Initialize()
AllowEvents = False
End Sub
Private Sub Check1_Click()
If AllowEvents = False Then Exit Sub
Select Case Check1.Value
Case 0 ' if proxy is disabled then
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF&
txtProxyAddress.Enabled = False
Case 1 ' if proxy is enabled then
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
End Sub
Private Sub Form_Load()
Dim objCreate As Object
Set objCreate = CreateObject("wscript.shell")
'NEVER use "On Error Resume Next".
On Error GoTo ProxyServerError
txtProxyAddress = objCreate.regread(ProxyServer)
On Error GoTo ProxyEnableError
Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
Select Case Check1.Value
Case 0
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF
txtProxyAddress.Enabled = False
Case 1
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
AllowEvents = True
FirstRuncheck
Exit Sub
ProxyServerError:
'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
' MsgBox "Error reading registry value:- ProxyServer"
Resume Next
' Exit Sub
ProxyEnableError:
'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
' MsgBox "Error reading registry value:- ProxyEnable"
Resume Next
' Exit Sub
End Sub
Private Sub Cmdchange_Click()
ProxySettings txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
Select Case Check1.Value
Case 0 ' if proxy is disabled then
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF&
txtProxyAddress.Enabled = False
Case 1 ' if proxy is enabled then
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
MsgBox "For settings to take affect, Please re-start Internet Explorer", vbOKOnly, "Restart IE"
End Sub
Private Sub ProxySettings(Address As String, Enable As Integer)
Dim objCreate As Object
Set objCreate = CreateObject("wscript.shell")
On Error GoTo ProxyServerWriteError
objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
On Error GoTo ProxyEnableWriteError
objCreate.RegWrite ProxyServer, Address, "REG_SZ"
Exit Sub
ProxyServerWriteError:
MsgBox "Error saving Proxy server", vbCritical, "Error!"
ProxyEnableWriteError:
MsgBox "Error saving Proxy status", vbCritical, "Error!"
End Sub
Private Sub menuExit_Click()
Unload Me
End Sub
Private Sub menuRestore_Click()
txtProxyAddress.Text = "" '<------
txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
Check1.Value = GetSetting("pr0xytool", "Settings", "Proxystatus", 0) ' Restore original proxy status (on/off)
ProxySettings txtProxyAddress, Check1.Value ' Save restored settings to main registry
MsgBox "Original Settings restored - " & txtProxyAddress.Text & vbNewLine & " Proxy Enabled - " & Check1.Value
End Sub
Public Sub FirstRuncheck()
Dim strRanbefore As String
On Error GoTo GetError
strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
If strRanbefore = 0 Then
On Error GoTo SaveError
SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
SaveSetting "Pr0xytool", "Settings", "ProxyStatus", CInt(Check1.Value) ' saves proxy status (on/off)
End If
Exit Sub
GetError:
MsgBox ("Error checking if program has ran before")
Exit Sub
SaveError:
MsgBox ("Error Saving Firstrun status")
Exit Sub
End Sub
Private Sub txtProxyAddress_Click()
MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
End Sub