Need Explanation of Cscript vs. Wscript (batch mode, console mode, interactive mode)

These are all so similar.  Most references just seem to describe them sequentially, without really pointing out any differences.

Can someone directly compare DIFFERENCES or give me some good link?  Aren't batch mode and console mode the same thing?

(interactivity, capabilities, switches to hide window, etc.)
Who is Participating?
Bill PrewConnect With a Mentor Commented:
Cscript vs. Wscript

The difference between Cscript and Wscript is that Cscript is the command-line version of the script host and Wscript is the graphical version. This difference isn’t really noticeable unless your script uses the Wscript.Echo command. As you’ve already seen, if you use Cscript your output from a Wscript.Echo statement will, by default, display to the command window; if you use Wscript that output will display in message boxes. Because of this, you need to consider what can happen if you change your default script host to Cscript. For example, what do you think will happen if your default script host is Cscript and you double-click the script file from Windows Explorer? Well, since the output is now going to the command prompt, Windows will open the command window, display the output, and then - here’s the … fun ... part - close the window. In other words, you’ll get a very brief glimpse of a command window that will disappear before you can actually see any of the output. Not very helpful. So be sure to keep this in mind if you decide to change the default script host.

One thing to note is that this difference in display is only with output that uses the Wscript.Echo statement. If you use the MsgBox function a message box will display whether you’re running under Cscript or Wscript; the same is true of the InputBox function.

There are other slight differences between the two, but Wscript.Echo is the most obvious and the one you’re likely to run into most often.

Further reading:
Batch files are true DOS commands, about as close to the kernal as you can get, and they run right in the command line interface of Windows with little to no modification (%%a instead of %a%) is about it.

WScript is Windows, and therefore not a good standard across platforms.

CScript and JavaScript are a little better across platforms.
DeadRatRacerConnect With a Mentor Commented:
To add to billprew's description, cscript is often more useful when performing automation tasks using VBScript of JScript. Having a pop-up window for every echo can be tedious and make running at startup or in the background impractical.

Windows batch files are capable of using either wscript or cscript, and other than output are interchangeable.

calling a console script under the Windows Command Prompt allows you to see any output your script generates, so you dont HAVE to lose the output.  For rapid 'one off' scripts that do not require user input, console scripts are my preferred type as you can pepper it with output to aid in debugging.

Anything that the user has to interact with I think is better off using wscript to get the windows interface as opposed to what may be termed 'a clunky looking DOS-like box'.

My 2c, billprew pretty much covered the rest!

 athomsfere - I'm not really sure that kernel statement is accurate under WindowsNT+ and later or even Win95 running in protected mode. CScript is a windows program that runs vb and js scripts and is not cross-platform, in particular because almost scripting anything complicated ends up calling MS WMI, DLLs, and methods to perform tasks that are windows-centric anyway.
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

What was the role of MS-DOS in Windows 95?

Technet script center - excellent resource!
ksuchyAuthor Commented:
Wow!!  You guys ROCK!!  (geniuses!!)

==~~<<!!**{{  T H A N K   Y O U  }}**!!>>~~==

I have started reading the articles you linked for me and will continue to do so.

Where I work, the bosses don't ever want a msg box, or even the millisecond flash of a console window, because the philosophy is to not 'disturb' the user, and keep our work hidden in the background/transparently.  Plus, we aren't allowed to GPO their machine into straight jackets, so I can't really assume the default host (normally wscript).  If I want feedback, I pipe to text files, or hope a real programmer will have mercy on me and make an event log object with methods I can use in vbscript.

But I can't go to 200 desktops each morning and open a shell and type  
>cscript mapDriveAndExecuteInvisibly.vbs

Before I close this question, can I please ask this:

Excluding changing the default host (which my bosses would never allow), how do I ensure that my automation scripts (logon scripts, scheduled scripts, and event triggered scripts) kick off or are executed by wscript or cscript exclusively, but still ensure that I don't accidentally open a msg box, console, etc??  

ksuchyAuthor Commented:

There's a SUB function listed on this page, which I guess I could keep in a separate file, and just call it on all my scripts when executed, to ensure that they restart using cscript.

As I'm not even sure how that SUB works, I wouldn't have a clue how to modify it to do the reverse (restart if not already executing using wscript), but I think this is a huge help (put me on the right tracks!).


One of the statements in that same 'newbie' forum thread above was:

"CScript is used when running scripts from the command line. WScript is used when running a script from the gui " 

That drives me nuts.  I'm not on the computer running this.  My scripts all kick off automatically, and hopefully transparently.  Most of them are a bit opaque to my tiny brain and I didn't even make them, but I have to try to figure them out, fix or maintain them.  

Can I just clarify this much: aren't batch mode and console mode the same thing???

They refer to ANY script (cscript or wscript) that executes without the familiar windows message boxes, right???  

And the guy who said that "Wscript is used when running a script from the gui" he was really just saying that assuming wscript is the default interpreter, that double clicking a vbscript will send it to wscript, and that wscript echo's things to little windows message boxes, when not piped to text files, right ????
Bill PrewCommented:
==> There's a SUB function listed on this page, which I guess I could keep in a separate file, and just
==> call it on all my scripts when executed, to ensure that they restart using cscript.

==> As I'm not even sure how that SUB works, I wouldn't have a clue how to modify it to do the reverse
==> (restart if not already executing using wscript), but I think this is a huge help (put me on the right
==> racks!).

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
     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.

Hope that helps some on that one.

Bill PrewCommented:
Yes, I think you have the idea on the difference and purpose of cscript versus wscript.  For me CSCRIPT is a "batch" mode, or as you say console mode, where you don't get prompted for things and output is written to the console, not a pop up window.  Wscript is used for what I think of as "interactive" scripts that might prompt the user for info in a pop up box, and supply their results in a pop up window, etc.

ksuchyAuthor Commented:
Awesome, Thanks Bill!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.