ForceCScript
Main
Sub Main
WScript.Echo "This script is running in the CScript script host"
WScript.Sleep 3000
End Sub
Sub ForceCScript()
'Declare local variables
Dim strHost
Dim strCmdLine
Dim objShell
Dim objFSO
'Determine the current script host
strHost = Right(WScript.FullName, 11)
strHost = LCase(strHost)
'Check if we need to restart ourselves
If strHost <> "cscript.exe" Then
'Create objects
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Build the command line
'Add the desired scripting host
strCmdLine = Chr(34) & objFSO.BuildPath(WScript.Path, "cscript.exe") & Chr(34)
'Add a dividing space
strCmdLine = strCmdLine & " "
'Add the path of the currently executing script
strCmdLine = strCmdLine & Chr(34) & WScript.ScriptFullName & Chr(34)
'Run the script
objShell.Run strCmdLine
'Destroy objects
Set objShell = Nothing
Set objFSO = Nothing
'Quit the script
WScript.Quit
End If
End Sub