Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

spaces and variable in path

1,068 views
Skip to first unread message

stay_t...@yahoo.com

unread,
Nov 15, 2008, 4:04:33 PM11/15/08
to
I am trying to write a script that runs a series of commands from a
server. The server from where the commands run depends upon where the
end user is located. At the start of the script, I ask for the name of
the server:
Wscript.StdOut.Write "Please enter SMS server name: "
strsvr = Wscript.StdIn.ReadLine

Then I start running the commands like this:
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "\\" & strsvr & "\foldername\foldername\foldername
\install.exe", , True

My problem is when there are spaces in the path. I know that using 3
sets of quotes solves the problem with spaces, but this does not work
when I use a variable in the middle of the entire path, like this:
wshshell.run "\\" & strsvr & """\foldername\folder name\folder name
\install.exe""", , True

Nor does assigning the path to a variable work, such as:
installPath = """\foldername\folder name\folder name\install.exe"""
wshshell.run "\\" & strsvr & installPath, , True

I have just started teaching myself vbscript, so I'm still very new to
this.

Any help would greatly appreciated

Tom Lavedas

unread,
Nov 15, 2008, 4:09:49 PM11/15/08
to

The quotes need to enclose the entire path. So, in this case, the
construct should look something like this ...

installPath = "\foldername\folder name\folder name\install.exe"

wshshell.run """\\" & strsvr & installPath & """", , True

Or use the Chr(34) construct instead ...

installPath = "\foldername\folder name\folder name\install.exe"

wshshell.run Chr(34) & "\\" & strsvr & installPath & Chr(34), , True

Tom Lavedas
-------------------

stay_t...@yahoo.com

unread,
Nov 15, 2008, 4:22:58 PM11/15/08
to

Worked like a charm!!!!

I cannot thank you enough. I've been struggling with this for days.

Tom Lavedas

unread,
Nov 16, 2008, 2:42:39 PM11/16/08
to

Glad to be of some assistance.

Tom Lavedas
-------------------

dfb...@gmail.com

unread,
Feb 6, 2013, 1:15:25 AM2/6/13
to
i know its a few years later but your idea of & Chr(34) has saved me a lot of time
i can now use the path variable for other parts of my script but cmd section now works also

before i had 2 sets of the same variable one with """variable""" and the otehr "variable", and like the op """ doesnt work if its in sections or in middle.

you are awesome

regards - Darren
0 new messages