Using variable (which includes spaces) in vbscript shell.run


  1. Posts : 2
    Windows 7 Home Premium 64 bit
       #1

    Using variable (which includes spaces) in vbscript shell.run


    Unable to find anything specific for this other than spaces in actual file paths. I know I can deal with this by using the actual path and file name enclosed by 3 quotes (inverted commas) but this would have to be changed each time I ran the script. Because thay would be very tedious I need the path and file name to be in the 2 variables as they will be constantly changing

    The path will be in var1 and the file name in var2 as follows:

    Var1 = "C:\Specials\Blues And Twos\"
    Var2 = "Luna Pic.jpg"

    Here is the relevent part of my script.

    Set shell = CreateObject("WScript.Shell")
    shell.Run Var1 & Var2, 1, false

    This is no problem running this if there are no spaces iin variables Var1 and Var2. Unfortunately there are in both so how can I get this to run. I know the answer lies in the placing of the quotes so I've tried various combinations but without success.

    Any help would be gratefully received.
      My Computer


  2. Posts : 3,788
    win 8 32 bit
       #2

    Welcome to the forurm it doesnt allow spaces but Itry to avoid spaces in names because of these kind of issues. One thing you can try, which is how you get around names with spaces in a vbscript is using triple quotes (""") to open and close your statement. Example: cscript.exe """%deployroot%\Applications\my appli with space\myScript.vbs"""
      My Computer


  3. Posts : 2
    Windows 7 Home Premium 64 bit
    Thread Starter
       #3

    Thanks for your reply Samuria but as I said it will not accept the 3 quotes as it treats a variable as a file path+name hence the rejection under "cannot find file". It does not recognise that the variable contains that information.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:57.
Find Us