vbscriptcommand-window

VBScript Command window - passing a command syntax


I'm trying to get a command to run in a cmd vindow via VBS. Just like this answer: How to keep the VBScript command window open during execution

The command I'm trying to issue is this, as written it works in a .cmd file.

"\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\dtexec" /x86 /f "\\path\folder\folder with space\Import.dtsx"

I've been unable to get it to work in the syntax from the above answer:

objShell.run "%comspec% /c ""SomeProgram.exe -R & pause""", 1, True

Figure it's a double quote issue, but I can't find it.

(I have to use the whole path to dtexec to force usage of the 16bit version.)

Followup: =======================================================

This works:

oShell.Run "%comspec% /C ""\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\dtexec"" /x86 /f c:\temp\Import.dtsx & Pause", 1, True

This does not:

oShell.Run "%comspec% /C ""\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\dtexec"" /x86 /f ""c:\temp\temp two\Import.dtsx"" & Pause", 1, True

nor this:

oShell.Run "%comspec% /C ""\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\dtexec /x86 /f c:\temp\temp two\Import.dtsx"" & Pause", 1, True

It's that space in the filename argument that is hosing it.


Solution

  • You don't need pause, just tell CMD to keep the window open after the command finishes (/k) instead of closing it (/c):

    objShell.Run "%comspec% /k program.exe -R", 1, True
    

    Nested double quotes are only required when you have a path with spaces in it, e.g.:

    objShell.Run "%comspec% /k ""C:\some folder\program.exe"" -R", 1, True
    

    Edit: If arguments in your commandline are paths with spaces as well you need quotes around each path and another set of quotes around the entire statement:

    objShell.Run "%comspec% /c """"C:\some folder\program.exe"" /p ""foo bar"" & pause""", 1, True