Question : Need Pros/Cons of various methods used to ensure vbscripts execute with cscript or wscript

I am so grateful for all the great super-genius programmers on EE!  Thanks in advance for taking time to help me again.

Please take a quick look at the tiny SUB function here:
http://www.visualbasicscript.com/Newbie-Cscript-vs-Wscript-m83649.aspx  

I'm going to venture a guess, that when you have any vbscript compiled, or triggered, or scheduled, or otherwise executing automatically (that you are not right there, to kick it off by double clicking, or typing in "cscript myscript.vbs" at a prompt), that there are other methods beyond the SUB routine I linked to above, which can be used to ensure interpretation of the script is done exclusively via wscript or cscript.  

Assuming you know of these, what are the pros/cons of these various programmatic (non-interactive) methods ???

Answer : Need Pros/Cons of various methods used to ensure vbscripts execute with cscript or wscript

When you break it down this sub isn't too bad to understand, let me see if I can clarify a bit:

 Sub ForceCScript()
     If InStr(UCase(WScript.FullName), "CSCRIPT.EXE") = 0 Then
         Dim objShell : Set objShell = CreateObject("WScript.Shell")
         objShell.Run "%comspec% /k cscript.exe " & Chr(34) & WScript.ScriptFullName & Chr(34), 1, False
         WScript.Quit()
     End If
 End Sub

ok, the first IF statement is determining if WSCRIPT.EXE or SCRIPT.EXE is currently running this script.  It does that by referencing a system value of WScript.Fullname and then looking for CSCRIPT.EXE in it.  If it isn't found, then we need to stop running, and restart in CSCRIPT.EXE mode.  So inside the IF block, we define a handle top the Shell opbject, and then use the Run methond it provides to launch an executable.  That executes a command as if it was entered at a command line prompt and basically runs this script a second time, but this time running it under CSRIPT.  After it starts that new copy of the script it does a Quit to end this running copy, which wasn't using CSCRIPT.

Okay, on to the rest of the question.  If you are scheduling or trying to execute a vbs script, you can either just "run" the filename.vbs file, or you can explicitly do something like cscript filename.vbs.  If you are running what are often referred to as batch scripts that don't involve windows activity, then I typically use a command line (which could be in the windows scheduler) of cscript //nologo filename.vbs followed by any parms I need to pass to it, and if desired redirecting the output to a text file.  This keeps it from displaying much to the screen at all.

If you don't know how the script will be run, and there is a possibility it can be run by a user double clicking on it, or just entering filename.vbs at a command line, and you want it to run in either cscript or wscript, then the SUB can be useful to force it into the desired run mode.

~bp
Random Solutions  
 
programming4us programming4us