如何使用命令行

时间:2016-10-20 09:49:29

标签: vbscript

在批处理文件中,我有以下命令:

WScript ABC.vbs

ABC.vbs

Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Hello"

当我运行批处理文件时,会出现一条带有“Hello”文本的弹出消息。但我想要的是在命令提示符窗口中显示消息“Hello”,就像我右键单击ABC.vbs然后选择“使用命令提示符打开”。

1 个答案:

答案 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.

相关问题