2013-10-23 63 views
0

我有一個示例代碼來啓用/禁用IE上的代理。VBS上的定時器使用情況

我想在此腳本上使用計時器。

如果啓用代理,並且如果用戶使用下面的腳本禁用代理,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 

回答

0

如果禁用代理,啓動一個隱藏的VBS(在WScript.Shell實例化對象Run法)至極等待(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" 
+0

感謝您的支持,但我需要代碼示例。你能幫忙嗎? –

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