vbs cmd path space

18,964

Paths with spaces are typically enclosed in quote characters ("). In VBScript, to insert a quote character into a string you use double quotes (""). So, your code should look like this:

oShell.Run "cmd /c Client\setupclient.exe /q /targetdir ""c:\program files\Microsoft CRM""", 1, true

Also, I'm not sure if cmd /c is actually needed here, so it might work this way as well:

oShell.Run "Client\setupclient.exe /q /targetdir ""c:\program files\Microsoft CRM""", 1, true
Share:
18,964
chr1s
Author by

chr1s

Updated on June 04, 2022

Comments

  • chr1s
    chr1s almost 2 years

    I would like to be able to call the following cmd command from within a vbs script:

    cmd Client\setupclient.exe /q /targetdir "c:\program files\Microsoft CRM"
    

    I came up with the following vbs script:

    Set oShell = WScript.CreateObject ("WScript.Shell") 
    oShell.Run "cmd /c Client\setupclient.exe /q /targetdir c:\program files\Microsoft CRM", 1, true
    

    As far as I am concerned, this would work properly if the targetdir had no spaces, e.g c:\bla. Then the app would be installed in that particular folder.

    The obvious question is, how can I define the targetdir with spaces as the path location.
    I tried to surround it with ' ' but that didn't work for me. Any suggestions?

    Cheers chris