Enable/Disable Proxy using VBScript

reference: http://stackoverflow.com/questions/19537553/timer-usage-on-vbs

OptionExplicit

Const HKCU = &H80000001
Const KEY = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Const VALUE = "ProxyEnable"
Const TITLE = "Disable IE Proxy"
Const PROXY = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"

Dim wmi
Dim iProx

Set wmi = GetObject("winmgmts:\\.\root\default:StdRegProv")

Call wmi.GetDWordValue(HKCU,KEY,VALUE,iProx)

SelectCase iProx
  Case1:
    IfMsgBox("Proxy is ENABLED. Do you want to disable it?", vbQuestion+vbYesNo, TITLE) = vbYesThen
      'disable, delay, then re-enable
      Call wmi.SetDwordValue(HKCU,KEY,VALUE,0)
      Call wmi.GetDWordValue(HKCU,KEY,VALUE,iProx)
      MsgBox("Proxy Disabled ("& iProx & ")" & vbCrLf & "Current Proxy: "& readFromRegistry(PROXY))
    EndIf
  Case0:
    IfMsgBox("Proxy is DISABLED. Do you want to enable it?", vbQuestion+vbYesNo, TITLE) = vbYesThen
      Call wmi.SetDwordValue(HKCU,KEY,VALUE,1)
      Call wmi.GetDWordValue(HKCU,KEY,VALUE,iProx)
      MsgBox("Proxy Enabled ("& iProx & ")" & vbCrLf & "Current Proxy: "& readFromRegistry(PROXY))
     EndIf
EndSelect

Set wmi = Nothing
WScript.Quit

function readFromRegistry (strRegistryKey)
    Dim WSHShell, value

    OnErrorResumeNext
    Set WSHShell = CreateObject("WScript.Shell")
    value = WSHShell.RegRead( strRegistryKey )

    if err.number <> 0then
        readFromRegistry= Err.Description
    else
        readFromRegistry=value
    endif

    set WSHShell = nothing
endfunction
 

Comments

Popular posts from this blog

c# console applicaton progress bar with spinner

Paging, sorting and searching in mvc + razor

C# SELF DESTRUCT CONSOLE APP