force a vbscript to run in CSCRIPT

There are several valid reasons to demand that a vbscript runs in CSCRIPT instead of WSCRIPT, like for example to allow the use of Standard Input or to prevent a separate popup for each Wscript.Echo line.

The following code can be copied and pasted at the top of your own scripts to force them to run in CSCRIPT:

If (right(Ucase(WScript.FullName),11)="WSCRIPT.EXE") Then
    Dim WshShell,args,objArgs,I
    Set WshShell = CreateObject("WScript.Shell")
    args=""
    If Wscript.Arguments.Count > 0 Then
        Set objArgs = WScript.Arguments
        For I = 0 to objArgs.Count - 1
            args = args & " " & objArgs(I)
        Next
    End If
    Set objDebug = WshShell.Exec ( "cscript.exe /NoLogo """ & Wscript.ScriptFullName & """" & args )

    ' Wait until the script exits
    Do While objDebug.Status = 0
        WScript.Sleep 100
    Loop

    ' Exit with CSCRIPT's return code
    WScript.Quit objDebug.ExitCode
End If

The code may look more complicated than necessary, that’s because it returns CSCRIPT‘s return code to the WSCRIPT engine, just in case this return code is monitored by the program that started the script in WSCRIPT.

In case you want to force a script to run in WSCRIPT instead, just substitute WSCRIPT.EXE for CSCRIPT.EXE.