![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 > ------------------- I cannot thank you enough. I've been struggling with this for days. |
My System Specs![]() |
| | #4 (permalink) |
| | 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. Tom Lavedas ------------------- |
My System Specs![]() |
![]() |
| 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 | |||