在批处理文件中,我有以下命令:
WScript ABC.vbs
在ABC.vbs
:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Hello"
当我运行批处理文件时,会出现一条带有“Hello”文本的弹出消息。但我想要的是在命令提示符窗口中显示消息“Hello”,就像我右键单击ABC.vbs
然后选择“使用命令提示符打开”。
答案 0 :(得分:2)
In addition to the two comments to use cscript.exe ABC.vbs
as your command line, here is a function you can put in your .vbs script to ensure it always runs with the cscript engine, no matter how it's called.
Sub checkengine
pcengine = LCase(Mid(WScript.FullName, InstrRev(WScript.FullName,"\")+1))
' BEGIN CALLOUT A
If Not pcengine="cscript.exe" Then
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
WScript.Quit
End If
' END CALLOUT A
End Sub
From this site: Forcing VBScript Files to Run in CScript Mode
Put Call checkengine
at the beginning of your vbscript. If it detects that cscript.exe is not in the command line, it relaunches the script with that engine.