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
  • 193,178
  • 25
  • 254
  • 328
user2567674
  • 171
  • 1
  • 3
  • 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

1 Answers1

-1

Of course yes, the Run command is supposed to return something. I was here because I was hesitant about the second parameter. I found it there : Documentation of Windows Script Host Run method, on vbsedit.com

Shell.Run returns the return value of the command line that it executes, so in this case, you will find the signification of the return code in the documentation of the Launch program, in the Test folder. (Test means what it means ...)

Of course it would ease the comprehension if the Launch program respected the conventions about the significations of the codes, but for a test you do not always enter into those details. Probably because of this, 87 remains me nothing. A missing file is a quite classical error, with code 2. But perhaps 2 would be for a data file.