我是一名业余 VB 脚本编写者。我正在制作一个脚本来检查两个文件之一是否存在,如果存在,则给出一个标记为“已安装”的标志。如果两个文件都不存在,则标记“未安装”。这是我的脚本...
Option Explicit
DIM fso
Set fso = CreateObject("Scripting.FileSystemObject")
CreateObject("WScript.Shell")
If (fso.FileExists("C:\Program Files (x86)\Dell\KACE\AMPAgent.exe")) OR (fso.FileExists("C:\Program Files\Dell\KACE\AMPAgent.exe")) Then
WScript.Echo("Installed")
WScript.Quit()
Else
WScript.Echo("Not Installed")
WScript.Quit()
End If
当我在 Windows 7 中运行它时它工作。当我将它添加到 BGInfo 时,它会抛出这个错误...
Error evaluating scripted field 'KACE'
Microsoft VBScript runtime error
Line 7, position 2
Variable is undefined: 'WScript'
[OK]
我认为我只需要一种方法来定义或调用 WScript 来执行操作,因为它显然不是通过 BGInfo 自行完成的,而我所做的也不起作用。我还没有在 StackOverflow 上看到任何可以帮助解决这个特殊问题的东西。
有什么想法吗?
最佳答案
BGInfo 实现了它自己的脚本宿主并且似乎没有模拟 WScript 对象。浏览 some snippets我在 Internet 上发现,在 BGInfo 中看起来就像普通的 Echo 一样有效。一个片段:
On Error Resume Next
call WScript.Echo(strReturn) 'for cmd line
call Echo(strReturn) 'for BGInfo
on error goto 0
注意 On Error 如何帮助它以任何一种方式工作。
关于windows - 在 BGInfo "Variable is undefined: ' WScript 中使用 VBScript 时出错“”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16725373/