我试图创建一个脚本进入启动应用程序,这将自动在我的工作场所设置代理。这个想法是这个,但我是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
有人能告诉我哪里出错了吗?
谢谢!
答案 0 :(得分: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