Scripting Tips

 

Make "cscript.exe" the Default Scripting Engines

The Windows Script Host offers two possible environments for running a script:

"wscript.exe":

Runs as part of the Windows GUI- text output appears as Windows message boxes.

"cscript.exe":

Runs inside a command line console- text output is sent to the console.

 

The "cscript.exe" variant is recommended for automated scripts because program execution continues even in case of a warning message or error.

 

A script can be started by explicitly specifying the script engine to use followed by the name of the script file to run, as in:

C:\Documents and Settings\Andreas\Scripts>cscript MyJob.wsf

A shorter command line can be created by just using the name of your script as a command, as in:

C:\Documents and Settings\Andreas\Scripts>MyJob.wsf

Or by omitting the file name extension:

C:\Documents and Settings\Andreas\Scripts>MyJob

However, this command will start the default script engine which is normally "wscript.exe." You can define the default script engine by entering the following command in once:

C:\Documents and Settings\Andreas\Scripts>cscript //h:cscript

This will create the following output:

         Microsoft (R) Windows Script Host Version 5.6
         Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
         The default script host is now set to "cscript.exe".

Now you can start your script just by entering its file name, and it will be executed with "cscript.exe."