0

我有一个示例代码可以在 IE 上启用/禁用代理。

我想在这个脚本上使用一个计时器。

如果启用代理并且如果用户使用以下脚本禁用代理,则 5 分钟后,代理将自动再次激活。脚本手动执行此操作,但我想使用计时器自动执行此操作。

如果代理已经启用,则不需要任何东西。它将始终启用。

谢谢你的帮助

Const HKEY_CURRENT_USER = &H80000001
Set objShell = CreateObject("WScript.Shell")
strPC = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

On Error Resume Next

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}! 
\\.\root\default:StdRegProv")

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

objReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

If dwValue = 1 Then
IEPrompt = MsgBox ("IE Proxy is currently ENABLED on " & strPC & _
".  Do you want to DISABLE it?", vbQuestion+vbYesNo, "Disable IE Proxy")
If IEPrompt = vbYes Then
    dwValue = 0
    objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue 
    MsgBox "IE Proxy is now DISABLED on " & strPC & _
    ".",vbInformation, "Disable IE Proxy"
    ElseIf IEPrompt = vbNo Then
        MsgBox "IE Proxy is still ENABLED on " & strPC & _
        ".",vbInformation, "Disable IE Proxy"
End If
    ElseIf dwValue = 0 Then
    IEPrompt = MsgBox ("IE Proxy is currently DISABLED on " & strPC & _
    ".  Do you want to ENABLE it?", vbQuestion+vbYesNo, "Enable IE Proxy")
    If IEPrompt = vbYes Then
        dwValue = 1
        objReg.SetDWORDValue     HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
        MsgBox "IE Proxy is now ENABLED on " & strPC & _
        ".",vbInformation, "Enable IE Proxy"
        ElseIf IEPrompt = vbNo Then
            MsgBox "IE Proxy is still DISABLED on " & strPC & _
            ".",vbInformation, "Enable IE Proxy"
End If
End If
4

2 回答 2

0

当您禁用代理时,启动一个隐藏的 vbs(实例化对象Run中的方法WScript.Shell)等待(WScript.Sleep)5 分钟,然后启用代理。

编辑

在您的代码中,禁用代理后

WScript.CreateObject("WScript.Shell").Run "wscript.exe waitandenableproxy.vbs", 0, false

waitandenableproxy.vbs

WScript.Sleep 300000
WScript.CreateObject("WScript.Shell").RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
于 2013-10-23T09:37:57.757 回答
0

这个怎么样?

Option Explicit

Const HKCU = &H80000001
Const KEY = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Const VALUE = "ProxyEnable"
Const TITLE = "Disable IE Proxy"
Const DELAY = 300000 '5 minutes in milliseconds

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 WScript.Sleep(DELAY)
      Call wmi.SetDwordValue(HKCU,KEY,VALUE,1)
    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)
    End If
End Select

Set wmi = Nothing
WScript.Quit
于 2013-10-23T12:53:57.907 回答