2015-03-03 50 views
0

我試圖創建一個腳本來進入,它會自動設置代理在我工作的啓動程序。這個想法是這樣的,但我是VBScript的新手,並且不斷收到錯誤。VBScript來啓用/禁用代理

Option Explicit 
Dim WSHShell, strSetting 
ans = msgbox("Are you working in the office?" , vbyesno) 
If ans = vbyes then 
Set WSHShell = WScript.CreateObject("WScript.Shell") 
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD" 
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "10.2.2.88:8090", "REG_SZ" 
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", "*.dev;*.test;*.local;<local>", "REG_SZ" 
else 
Set WSHShell = WScript.CreateObject("WScript.Shell") 
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD" 
End If 

有人可以告訴我我要去哪裏嗎?

謝謝!

回答

2

假設你的錯誤的東西如下:

==>cscript //nologo D:\VB_scripts\SO\28832310.vbs 
28832310.vbs(3, 1) Microsoft VBScript runtime error: Variable is undefined: 'ans' 

不言自明的消息,恕我直言。正如您已正確使用Option Explicit聲明(強制在腳本中明確聲明所有變量),只需添加ans變量聲明,即使用

Dim WSHShell, strSetting, ans