我需要知道vbscript中PATH中是否有可执行文件。 在* nix中,我会使用'which'命令来实现。 我在vbscript中使用了什么? 解决方案需要与WinXP兼容,因此'where'命令不适合我。
答案 0 :(得分:1)
我想出了这个:
Set wshShell = WScript.CreateObject ("WSCript.shell")
On Error Resume Next
wshshell.run "your_exec", 6, True
If Err.Number <> 0 Then
WshShell.Popup(Err.Number)
' Handle error
Err.Clear
End If
On Error Goto 0
set wshshell = nothing
your_exec
必须是以可立即返回的方式调用可执行文件,如果该可执行文件不提供某些命令行选项,则可能会出现问题。在我的情况下,我只是调用可执行文件来显示其版本:my.exe -version
。