30

I need to launch programs in my local system using VBScript. But I am having trouble with the syntax. This is what I am using right now -

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("iexplore")
Set objShell = Nothing

The above code successfully launches IE. I want to launch other browsers. But, if I use -

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("c:\Program Files\Mozilla Firefox\firefox.exe")
Set objShell = Nothing

it is throwing an error saying that the file or path was not found. I am not sure how the parameter inside the Run() function is taken - should I give the path to an EXE or should I give some DOS commands?!

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188

7 Answers7

59

Try:-

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""c:\Program Files\Mozilla Firefox\firefox.exe""")
Set objShell = Nothing

Note the extra ""s in the string. Since the path to the exe contains spaces it needs to be contained with in quotes. (In this case simply using "firefox.exe" would work).

Also bear in mind that many programs exist in the c:\Program Files (x86) folder on 64 bit versions of Windows.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • 1
    Hi, thanks! I got confused with the quotes :D But one note - using simply "firefox.exe" didn't work. –  Aug 27 '09 at 11:14
  • 4
    you can use `objShell.Run("""%ProgramFiles%\Mozilla Firefox\firefox.exe""")` to get round the 64-bit problem –  Jun 20 '11 at 16:59
  • 2
    Not really Jack. Firefox might still be installed under %ProgramFiles(x86)%. – mgr326639 Dec 19 '11 at 13:21
  • 2
    In the event you want to pass parameters to the exe, do not include them within the `"""` on the path, do the following: `objShell.Run("""c:\Program Files\Mozilla Firefox\firefox.exe""" & " -p1 someValue")` – Matt M Oct 21 '19 at 14:17
3

You van use Exec

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Exec("c:\Program Files\Mozilla Firefox\firefox.exe")
Set objShell = Nothing
nimday
  • 333
  • 3
  • 9
  • 1
    This answer is identical to the above one, except it is slightly wrong because it doesn't include the double quotes around the program name. – Stephen Holt Feb 14 '14 at 10:51
  • 1
    This answer is nearly identical to the above one, except it eliminates the need for several quotes, and it does work. – F-3000 Feb 20 '14 at 18:32
  • Although, Exec is not allowed to start programs from C:\Users\user\Appdata\Local, whereas Run can start apps from there. (TeamSpeak 3 installs there, for me at least it did) – F-3000 Feb 20 '14 at 18:54
3
set shell=CreateObject("Shell.Application")
' shell.ShellExecute "application", "arguments", "path", "verb", window
shell.ShellExecute  "slipery.bat",,"C:\Users\anthony\Desktop\dvx", "runas", 1
set shell=nothing 
weird
  • 31
  • 1
2

It's working with

Set WSHELL = CreateObject("Wscript.Shell")
WSHELL.Exec("Application_Path")

But what should be the parameter in case we want to enter the application name only

e.g in case of Internet Explorer

WSHELL.Run("iexplore")
phuclv
  • 37,963
  • 15
  • 156
  • 475
Milan Kumar
  • 361
  • 1
  • 6
  • 16
1
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("firefox")
Set objShell = Nothing

Please try this

1

find an .exe file for the application you want to run example iexplore.exe and firefox.exe and remove .exe and use it in objShell.Run("firefox")

I hope this helps.

-10

Copy the folder, firefox.exe is in and place in the c:\ only. The script is having a hard time climbing your file tree. I found that when I placed the *.exe file in the c:\ it eliminated the error message " file not found."

Shangz
  • 11