![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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" 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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). 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 Specs![]() |
![]() |
| 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 | |||