VBScript, a subset of Visual Basic, is a free programming language that anyone can use to create useful Windows applications. By adding just a few statements to a ".vbs" text file, you can write to text files and even launch EXE programs using a "Run" command. This command comes in handy when you wish to create shortcuts to frequently used programs. Developers can also use the "Run" command inside more complex VBScript applications to launch external EXE programs as needed.
- Skill level:
- Moderately Easy
Other People Are Reading
Open Notepad and paste the following code into a new document:
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim status Code
exeName = "%windir%\notepad"
status Code = WshShell.Run (exeName, 1, true)
MsgBox("End of Program")
This VBScript code creates a "Shell" object on line 1. Note the value of "exeName." This variable holds the name of the EXE you wish to run. That name is the path to Notepad in this example. If you wanted to run an EXE program named "MusicLab.exe" located on your "C" drive, you would make the fourth statement appears as follows:
exeName = "C:\MusicLab.exe"
Leave the value of "exeName" unchanged for now. The next statement executes the "Run" command. The "Run" command runs the EXE specified in the "exeName" variable. The second parameter, "1", in the "Run" command tells VBScript how you would like the EXE's window to appear when it opens. A value of "1" causes VBScript to display a normal window. The final value in the "Run" command, "true" causes the VBScript program to pause until the EXE that it runs closes. The final statement displays a message box that lets you know that the VBScript completed.
Click Notepad's "File" button, and then click "Save As." The Save As window opens. This window allows you to save your VBScript program.
Type a name for the program, such as "MyScript" in the "File Name" text box. Append ".vbs" to the end of that name. For instance, if you choose "MyScript" as the file name, type "MyScript.vbs" (without the quotes) in the file name text box and click "Save." This saves the file as a VBScript file.
Open Windows Explorer and locate the file. Double click the file. It runs and a new instance of Notepad. The VBScript program pauses after Notepad opens because you passed "1" to the "Run" command. If you had passed 0 instead, the VBScript would not pause.
Close Notepad. The program resumes execution and displays the message box that says, "End of Program."
Tips and warnings
- Many times, you may not care how an EXE's window looks when you use VBScript to launch the EXE. This example uses a window style of "1," as seen in the "Run" command described previously. The "1" value activates the window and displays it in normal mode. However, you could pass "2" to the "Run" command instead. The number "2" tells VBScript to activate the EXE's window and minimise it. Ten window styles exist. Each style displays the EXE's window in a different way. You can find tables showing those styles on websites that discuss VBScript and the "WindowStyle" parameter.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for