Reputation: 11
In batch file I have the command below:
WScript ABC.vbs
In ABC.vbs
:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Hello"
When I run the batch file there is a pop-up message with the text "Hello". But what I want is showing the message "Hello" in the Command Prompt window like I do the right click on ABC.vbs
and then select "Open with command prompt".
Upvotes: 1
Views: 15118
Reputation: 1702
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.
Upvotes: 4