How to Execute Windows Script Host
System administrators use Windows Script Host (WSH) files to manage files, update the registry, and perform advanced networking tasks. Windows Script Host uses very little memory and supports multiple scripting languages such as VBScript and JScript. Run WSH files in graphical user interface mode, or execute them from the Windows command line. If you have no programming skills, you can still enjoy the time-saving benefits provided by Windows Script Host.
Instructions
-
Create Test File
-
1
Open Notepad and add the following text to a new document:
WSH.Echo( "Testing" );
This is a WSH command that displays the word "Testing".
-
2
Click "File", and then "Save As". The "Save As" window will open and display your files and folders. Navigate to a folder where you want to save the file.
-
-
3
Enter a name for the file in the "File Name" text box. Give the file an extension of ".js". For example, if you want to name the file "Test1", enter "Test1.js" (without the quotes) in the text box. Click "Save". Notepad will save the file as a JScript file in the folder that you selected.
Execute Test File
-
4
Open Windows Explorer and navigate to the folder that contains the file.
-
5
Double-click the file. Windows Script Host will execute the file and display "Testing" in a pop-up window.
-
6
Click the Windows "Start" menu. Type "run" and press "Enter". If you use Windows XP, click "Run" to open the "Run" window.
-
7
Type "cmd" and press "Enter". The command window will open.
-
8
Type Cscript.exe xyz. Replace xyz with the full path name of the file that you created. For instance, if you saved the file as "C:\Myfolder\Test1.js," type the following in the "Command" window:
Cscript "C:\Myfolder\Test1.js"
Windows Script Host will execute the file and display a WSH log followed by the "Testing" message. The results will appear in the "Command" window.
-
9
Type the command again. This time, add "//NoLogo" (without the quotes) after the "Cscript" command. Instead of typing "Cscript C:\Myfolder\Test1.js," type the following instead:
Cscript //NoLogo C:\Myfolder\Test1.js
"//NoLogo" is a command line switch. Windows Script Host has several command line switches that you can add to a "Cscript" command. The "//NoLogo" switch suppresses the WSH logo.
-
10
Press "Enter" to execute the command. The test message will appear without the WSH logo.
-
1
Tips & Warnings
As the steps show, double-clicking a Windows Script Host file in Windows Explorer runs the file and displays results in a window. Running the file in the "Command" window displays results in the "Command" window. You can execute commands either way. Run a WSH file in the Command window when you need to use a command line switch.
References
Resources
- Photo Credit business lady 4 image by Paul Moore from Fotolia.com