Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - spaces and variable in path

Reply
 
Old 11-15-2008   #1 (permalink)
stay_tuned001


 
 

spaces and variable in path

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

My System SpecsSystem Spec
Old 11-15-2008   #2 (permalink)
Tom Lavedas


 
 

Re: spaces and variable in path

On Nov 15, 4:04*pm, stay_tuned...@xxxxxx wrote:
Quote:

> 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
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
-------------------
My System SpecsSystem Spec
Old 11-15-2008   #3 (permalink)
stay_tuned001


 
 

Re: spaces and variable in path

On Nov 15, 4:09*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
Quote:

> On Nov 15, 4:04*pm, stay_tuned...@xxxxxx wrote:
>
>
>
Quote:

> > 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
>
Quote:

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

> > 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
>
Quote:

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

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

> > Any help would greatly appreciated
>
> 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
> -------------------
Worked like a charm!!!!

I cannot thank you enough. I've been struggling with this for days.
My System SpecsSystem Spec
Old 11-16-2008   #4 (permalink)
Tom Lavedas


 
 

Re: spaces and variable in path

On Nov 15, 4:22*pm, stay_tuned...@xxxxxx wrote:
Quote:

> On Nov 15, 4:09*pm, Tom Lavedas <tglba...@xxxxxx> wrote:
>
>
>
Quote:

> > On Nov 15, 4:04*pm, stay_tuned...@xxxxxx wrote:
>
Quote:
Quote:

> > > 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
>
Quote:
Quote:

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

> > > 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
>
Quote:
Quote:

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

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

> > > Any help would greatly appreciated
>
Quote:

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

> > installPath = "\foldername\folder name\folder name\install.exe"
> > wshshell.run """\\" & strsvr & installPath & """", , True
>
Quote:

> > Or use the Chr(34) construct instead ...
>
Quote:

> > installPath = "\foldername\folder name\folder name\install.exe"
> > wshshell.run Chr(34) & "\\" & strsvr & installPath & Chr(34), , True
>
Quote:

> > Tom Lavedas
> > -------------------
>
> Worked like a charm!!!!
>
> I cannot thank you enough. *I've been struggling with this for days.
Glad to be of some assistance.

Tom Lavedas
-------------------
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Spaces in script path PowerShell
VBS script with spaces in executable path VB Script
Re: running a program with spaces in Path with invoke-expression PowerShell
invoke-expression with .exe that has spaces in its path PowerShell
script with spaces in the path PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46