5. VbScript | Run Command

Today we are going to talk about the run command. This command allows you to open applications outside of Vb Script.

Output:

When you run the Vbscript, the Microsoft Paint application is opened.


To open a website:

Or:

Output:

The internet browser is opened to the website google.com.

The reason why you’d want to store CreateObject(“wscript.shell”) as variable a, is because you would want to repeat that function several times in your code. Like so:

Output:

A browser to Google.com opens and then the application Microsoft Paint opens.


To open a folder directory:

The directory varies from computer to computer, you simply put the directory pathway between quotations ” “.

ie. 3

To open a file in a directory:

Add the directory & the name of the file itself. If you don’t know what the directory is, right-click the file and choose properties. You’ll see the directory listed as location, and all you have to do is add the name of the file itself (with the extension ie. .txt, .exe, .docx):

4


For a directory name that has spaces in it, you add 2 more quotations to each side, like so:

Without the set of double quotations added “” “”, the vbscript stops reading at the space and so reads it as ‘why’ instead of ‘why not’. Because the vbscript cuts off at ‘why’, it doesn’t read the .txt extension, and ends up looking for a folder called ‘why’.


What's Your Opinion?