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 - VBS script with spaces in executable path

Reply
 
Old 08-26-2008   #1 (permalink)
Tyler Durden


 
 

VBS script with spaces in executable path

I'm trying to write a vbs to run vncviewer on a relative path. The following
code works, except when the path has spaces:

Dim LaunchDir, FSO, WSHShell
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")
LaunchDir = FSO.GetFolder(".")

wSHShell.Run LaunchDir & "\vncviewer.exe -notoolbar -autoscaling
myhost.dyndns.org"

Where's the error?
Any help would be appreciated.




My System SpecsSystem Spec
Old 08-27-2008   #2 (permalink)
James Whitlow


 
 

Re: VBS script with spaces in executable path

"Tyler Durden" <abuse@xxxxxx> wrote in message
news:e36RBu%23BJHA.4340@xxxxxx
Quote:

> I'm trying to write a vbs to run vncviewer on a relative path. The
> following
> code works, except when the path has spaces:
>
> Dim LaunchDir, FSO, WSHShell
> Set FSO = CreateObject("Scripting.FileSystemObject")
> Set WSHShell = WScript.CreateObject("WScript.Shell")
> LaunchDir = FSO.GetFolder(".")
>
> wSHShell.Run LaunchDir & "\vncviewer.exe -notoolbar -autoscaling
> myhost.dyndns.org"
>
> Where's the error?
> Any help would be appreciated.
Trying changing your 'Run' line to (watch for wrapping):

wSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
myhost.dyndns.org"

Also, if you are only using the 'Scripting.FileSystemObject' to get the
current directory and nothing else, you can get it from 'WScript.Shell' &
remove the instantiation of 'Scripting.FileSystemObject'

LaunchDir = WSHShell.CurrentDirectory

FYI: The '.CurrentDirectory' method is read/write, so you can use it to
change the current directory as well.



My System SpecsSystem Spec
Old 08-27-2008   #3 (permalink)
Tyler Durden


 
 

Re: VBS script with spaces in executable path

James, tested here and worked perfectly. And is a better solution than mine.
Thank you.


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:%23ZKPDgGCJHA.2480@xxxxxx
Quote:

> "Tyler Durden" <abuse@xxxxxx> wrote in message
> news:e36RBu%23BJHA.4340@xxxxxx
Quote:

>> I'm trying to write a vbs to run vncviewer on a relative path. The
>> following
>> code works, except when the path has spaces:
>>
>> Dim LaunchDir, FSO, WSHShell
>> Set FSO = CreateObject("Scripting.FileSystemObject")
>> Set WSHShell = WScript.CreateObject("WScript.Shell")
>> LaunchDir = FSO.GetFolder(".")
>>
>> wSHShell.Run LaunchDir & "\vncviewer.exe -notoolbar -autoscaling
>> myhost.dyndns.org"
>>
>> Where's the error?
>> Any help would be appreciated.
>
> Trying changing your 'Run' line to (watch for wrapping):
>
> wSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
> myhost.dyndns.org"
>
> Also, if you are only using the 'Scripting.FileSystemObject' to get the
> current directory and nothing else, you can get it from 'WScript.Shell' &
> remove the instantiation of 'Scripting.FileSystemObject'
>
> LaunchDir = WSHShell.CurrentDirectory
>
> FYI: The '.CurrentDirectory' method is read/write, so you can use it to
> change the current directory as well.
>
>
>

My System SpecsSystem Spec
Old 08-27-2008   #4 (permalink)
Tyler Durden


 
 

Re: VBS script with spaces in executable path

James, just to make sure, the following is the complete script. Could it be
optimized/cleaned in any other way?

Dim LaunchDir, FSO, WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
LaunchDir = WSHShell.CurrentDirectory

WSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
myhost.dyndns.org"


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:%23ZKPDgGCJHA.2480@xxxxxx
Quote:

> "Tyler Durden" <abuse@xxxxxx> wrote in message
> news:e36RBu%23BJHA.4340@xxxxxx
Quote:

>> I'm trying to write a vbs to run vncviewer on a relative path. The
>> following
>> code works, except when the path has spaces:
>>
>> Dim LaunchDir, FSO, WSHShell
>> Set FSO = CreateObject("Scripting.FileSystemObject")
>> Set WSHShell = WScript.CreateObject("WScript.Shell")
>> LaunchDir = FSO.GetFolder(".")
>>
>> wSHShell.Run LaunchDir & "\vncviewer.exe -notoolbar -autoscaling
>> myhost.dyndns.org"
>>
>> Where's the error?
>> Any help would be appreciated.
>
> Trying changing your 'Run' line to (watch for wrapping):
>
> wSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
> myhost.dyndns.org"
>
> Also, if you are only using the 'Scripting.FileSystemObject' to get the
> current directory and nothing else, you can get it from 'WScript.Shell' &
> remove the instantiation of 'Scripting.FileSystemObject'
>
> LaunchDir = WSHShell.CurrentDirectory
>
> FYI: The '.CurrentDirectory' method is read/write, so you can use it to
> change the current directory as well.
>
>
>

My System SpecsSystem Spec
Old 08-27-2008   #5 (permalink)
James Whitlow


 
 

Re: VBS script with spaces in executable path

"Tyler Durden" <abuse@xxxxxx> wrote in message
news:OldexvGCJHA.1632@xxxxxx
Quote:

> James, just to make sure, the following is the complete script. Could it
> be optimized/cleaned in any other way?
>
> Dim LaunchDir, FSO, WSHShell
> Set WSHShell = WScript.CreateObject("WScript.Shell")
> LaunchDir = WSHShell.CurrentDirectory
>
> WSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
> myhost.dyndns.org"
I personally think it looks good. Others in the group might have some
helpful comments, though.

The only things that I would do differently would be to add 'Option
Explicit' as the first line to force variable declaration and use some form
of Hungarian Notation to indicate what type your variables are (string,
integer, object, etc.). I think most people prefer 3 letter abbreviations
(ex: strLaunchDir, objWSHShell), I personally prefer 1 letter abbreviations
(ex: sLaunchDir, oWSHShell).


My System SpecsSystem Spec
Old 08-27-2008   #6 (permalink)
Tyler Durden


 
 

Re: VBS script with spaces in executable path

Thank you.


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:uBDZfgHCJHA.2476@xxxxxx
Quote:

> "Tyler Durden" <abuse@xxxxxx> wrote in message
> news:OldexvGCJHA.1632@xxxxxx
Quote:

>> James, just to make sure, the following is the complete script. Could it
>> be optimized/cleaned in any other way?
>>
>> Dim LaunchDir, FSO, WSHShell
>> Set WSHShell = WScript.CreateObject("WScript.Shell")
>> LaunchDir = WSHShell.CurrentDirectory
>>
>> WSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
>> myhost.dyndns.org"
>
> I personally think it looks good. Others in the group might have some
> helpful comments, though.
>
> The only things that I would do differently would be to add 'Option
> Explicit' as the first line to force variable declaration and use some
> form of Hungarian Notation to indicate what type your variables are
> (string, integer, object, etc.). I think most people prefer 3 letter
> abbreviations (ex: strLaunchDir, objWSHShell), I personally prefer 1
> letter abbreviations (ex: sLaunchDir, oWSHShell).
>

My System SpecsSystem Spec
Old 08-29-2008   #7 (permalink)
Al Dunbar


 
 

Re: VBS script with spaces in executable path


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:uBDZfgHCJHA.2476@xxxxxx
Quote:

> "Tyler Durden" <abuse@xxxxxx> wrote in message
> news:OldexvGCJHA.1632@xxxxxx
Quote:

>> James, just to make sure, the following is the complete script. Could it
>> be optimized/cleaned in any other way?
>>
>> Dim LaunchDir, FSO, WSHShell
>> Set WSHShell = WScript.CreateObject("WScript.Shell")
>> LaunchDir = WSHShell.CurrentDirectory
>>
>> WSHShell.Run """" & LaunchDir & "\vncviewer.exe"" -notoolbar -autoscaling
>> myhost.dyndns.org"
>
> I personally think it looks good. Others in the group might have some
> helpful comments, though.
>
> The only things that I would do differently would be to add 'Option
> Explicit' as the first line to force variable declaration and use some
> form of Hungarian Notation to indicate what type your variables are
> (string, integer, object, etc.). I think most people prefer 3 letter
> abbreviations (ex: strLaunchDir, objWSHShell), I personally prefer 1
> letter abbreviations (ex: sLaunchDir, oWSHShell).
Personally, I mistrust the current directory and prefer to explicitly use
the directory where the script is located, i.e.:

replace( WScript.ScriptFullName, WScript.ScriptName, "vncviewer.exe")

This will give the full path to a file called "vncviewer.exe" located in the
same directory as the script itself - even if the current directory has been
changed for some reason, or is pointing elsewhere in case your script is
being executed by another script and not by double-clicking in explorer.

Some will point out that the above replace reference will fail in the event
that the path includes a folder that is a superset of the name of the
script. A more bullet-proof method would use the GetParent method of the
file system object. As an aside, it is almost always better to use the
filename parsing capabilities of FSO instead of string concatenation and
sub-stringing methods to calculate file paths.

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Spaces in script path PowerShell
Re: How to run an executable with spaces in the command line PowerShell
How to run an executable with spaces in the command line PowerShell
path to executable Software
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