3

I'm trying to run a program (with argument /config) using Shell.Run from VBS. However I'm having an exit code = 87 (cannot find the file specified).

1st piece of code I've tried:

strCommand = """c:\Program Files\Test\launch.exe""" & " /config:C:\sample.xml"
intExit = objShell.Run(strCommand, 0, True)

2nd piece of code:

Dim FileExe, Argum
FileExe = "%ProgramFiles%\Test\launch.exe"
Argum = "/config:C:\sample.xml"

RunMe FileExe, Argum

Function RunMe(FileExe, Argum)
    Dim Titre, ws, Command, Exec
    Titre = "Execution avec argument"
    Set ws = CreateObject("WScript.Shell")
    command = "cmd /c "& qq(FileExe) & " " & Argum &" "
    Msgbox command, 64, Titre
    Exec = ws.Run(command, 0, True)
End Function

Function qq(str)
    qq = chr(34)& str &chr(34)
End Function
Ansgar Wiechers
  • 184,186
  • 23
  • 230
  • 299
user2567674
  • 171
  • 1
  • 2
  • 15
  • Try this - http://stackoverflow.com/questions/16087470/run-command-line-command-from-vbs – Vishnu Prasad Kallummel Jul 10 '13 at 11:39
  • 1
    The quotes look OK to me. Also, if the executable couldn't be found, the script should terminate with an error 80070002. There shouldn't be anything returned by the `Run` method. Did you make sure that `C:\sample.xml` exists? – Ansgar Wiechers Jul 10 '13 at 13:35
  • Just to check, you are intentionally hiding the program, correct? The 0 in your arguments makes it where the window will be invisible. I would first try it set to 1, where it will be visible, and only change it to 0 when you are sure it works. This may also make it where you can see any errors. – trlkly Aug 17 '17 at 17:22
  • (just realized this was an old question.) – trlkly Aug 17 '17 at 17:23

0 Answers0