How to Run EXE in VBScript
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.
Open Notepad and paste the following code into a new document:Set WshShell = WScript.CreateObject("WScript.Shell")Dim exeNameDim statusCodeexeName = "%windir%\notepad" statusCode = 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."