This is the function that I use to ensure a script is running with the appropriate host. Just call it at the start of the script. Note that it will not work with a script that takes arguments on the command line. That is a simple change to the function but I have not had time to make it yet.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
'' Function: EnsureRunningUnder strInt, nWindowType
'' Purpose: Ensures that the script is being run with the specified
'' interpreter.
'' Takes: strInt - A string specifying the interpreter to use.
'' valid strings are "cscript" or "wscript"
'' nWindowType - An int specifying the window behavior of
'' the process that will be created. This is passed
'' directly to the .Run method of the WScript.Shell
'' object. See the WSH documentation for valid values.
'' Returns: NOTHING
'' ToDo: Make it handle script arguments
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub EnsureRunningUnder(strInt, nWindowType)
Dim oWsh:Set oWsh = CreateObject("WScript.Shell")
Dim strThisScript
Dim strRunCommand
Dim strIntPath
Dim strRunningInt
Dim arrIntPathParts
Select Case UCase(strInt)
Case "WSCRIPT", "WSCRIPT.EXE"
strInt = "wscript.exe"
Case "CSCRIPT", "CSCRIPT.EXE"
strInt = "cscript.exe"
Case Else
Exit Sub
End Select
arrIntPathParts = Split(WScript.FullName, "\")
strRunningInt = arrIntPathParts(UBound(arrIntPathParts))
arrIntPathParts(UBound(arrIntPathParts)) = ""
strIntPath = Join(arrIntPathParts, "\")
If UCase(strInt) <> UCase(strRunningInt) Then
strRunCommand = strIntPath & strInt & " " & Chr(34) & WScript.ScriptFullName & Chr(34)
oWsh.Run strRunCommand, nWindowType, False
WScript.Quit
End If
End Sub 'EnsureRunningUnder
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]