Enable/Disable Proxy using VBScript
reference: http://stackoverflow.com/questions/19537553/timer-usage-on-vbs
Option Explicit
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)
Select Case iProx
Case 1:
If MsgBox("Proxy is ENABLED. Do you want to disable it?", vbQuestion+vbYesNo, TITLE) = vbYes Then
'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))
End If
Case 0:
If MsgBox("Proxy is DISABLED. Do you want to enable it?", vbQuestion+vbYesNo, TITLE) = vbYes Then
Call wmi.SetDwordValue(HKCU,KEY,VALUE,1)
Call wmi.GetDWordValue(HKCU,KEY,VALUE,iProx)
MsgBox("Proxy Enabled ("& iProx & ")" & vbCrLf & "Current Proxy: "& readFromRegistry(PROXY))
End If
End Select
Set wmi = Nothing
WScript.Quit
function readFromRegistry (strRegistryKey)
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )
if err.number <> 0 then
readFromRegistry= Err.Description
else
readFromRegistry=value
end if
set WSHShell = nothing
end function
Option Explicit
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)
Select Case iProx
Case 1:
If MsgBox("Proxy is ENABLED. Do you want to disable it?", vbQuestion+vbYesNo, TITLE) = vbYes Then
'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))
End If
Case 0:
If MsgBox("Proxy is DISABLED. Do you want to enable it?", vbQuestion+vbYesNo, TITLE) = vbYes Then
Call wmi.SetDwordValue(HKCU,KEY,VALUE,1)
Call wmi.GetDWordValue(HKCU,KEY,VALUE,iProx)
MsgBox("Proxy Enabled ("& iProx & ")" & vbCrLf & "Current Proxy: "& readFromRegistry(PROXY))
End If
End Select
Set wmi = Nothing
WScript.Quit
function readFromRegistry (strRegistryKey)
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )
if err.number <> 0 then
readFromRegistry= Err.Description
else
readFromRegistry=value
end if
set WSHShell = nothing
end function
Comments
Post a Comment