Today we are going to talk about the run command. This command allows you to open applications outside of Vb Script.
CreateObject("wscript.shell").run "mspaint.exe"
Output:
When you run the Vbscript, the Microsoft Paint application is opened.
To open a website:
CreateObject("wscript.shell").run "www.google.com"
Or:
set a=CreateObject("wscript.shell") a.run "www.google.com"
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:
set a=CreateObject("wscript.shell") a.run "www.google.com" a.run "mspaint.exe"
Output:
A browser to Google.com opens and then the application Microsoft Paint opens.
To open a folder directory:
CreateObject("wscript.shell").run "C:\user\user-name\downloads"
The directory varies from computer to computer, you simply put the directory pathway between quotations ” “.
ie.
To open a file in a directory:
CreateObject("wscript.shell").run "C:\user\user-name\desktop\why.txt"
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):
For a directory name that has spaces in it, you add 2 more quotations to each side, like so:
CreateObject("wscript.shell").run """C:\user\user-name\desktop\why not.txt"""
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’.