Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2010-08-20
Medium Priority
Last Modified: 2012-08-13
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.)
Question by:ksuchy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
LVL 14

Expert Comment

ID: 33487276
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.
LVL 58

Accepted Solution

Bill Prew earned 1000 total points
ID: 33487431
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:


Assisted Solution

DeadRatRacer earned 1000 total points
ID: 33491319
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.
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why


Expert Comment

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

Technet script center - excellent resource!

Author Comment

ID: 33511336
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??  


Author Comment

ID: 33512278
REF: http://www.visualbasicscript.com/Newbie-Cscript-vs-Wscript-m83649.aspx

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 ????
LVL 58

Expert Comment

by:Bill Prew
ID: 33515277
==> 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.

LVL 58

Expert Comment

by:Bill Prew
ID: 33515316
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.


Author Comment

ID: 33516847
Awesome, Thanks Bill!

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question