Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vb Script Doesn't Like Folders With Spaces In Names? 3

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
I have a simple script to display an image file passed as a parameter using internet explorer. It works great with iexplore.exe in C:\.

Code:
Option Explicit

Dim MyParam1
Dim ObjShell
Dim RunIt

If Wscript.Arguments.Count <> 1 Then
	Wscript.echo "Incorrect Parameters.  One required."
Else
	MyParam1 = Wscript.Arguments.Item(0)
	Wscript.Echo "Params: " & MyParam1 
End If


Set objShell = CreateObject("WScript.Shell")
RunIt = "iexplore.exe " & MyParam1
Wscript.Echo Runit
objShell.Run Runit


The same script pointing to the standard location of iexplore.exe
in Program Files/internet explorer/ does not work. I get the error "Line 18, char 1. the system cannot find the file specified". I don't have a clue why.

Code:
Option Explicit

Dim MyParam1
Dim ObjShell
Dim RunIt

If Wscript.Arguments.Count <> 1 Then
	Wscript.echo "Incorrect Parameters.  One required."
Else
	MyParam1 = Wscript.Arguments.Item(0)
	Wscript.Echo "Params: " & MyParam1 
End If


Set objShell = CreateObject("WScript.Shell")
RunIt = "C:\Program Files\Internet Explorer\iexplore.exe " & MyParam1
Wscript.Echo Runit
objShell.Run Runit

Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
You'll need to quote the entire file path that contains a space such as:
Code:
RunIt = Chr(34) & "C:\Program Files\Internet Explorer\iexplore.exe " & Chr(34) & MyParam1

The space character is seen as a delimiter on the command line, so it is looking for "C:\Program" as a command with "Files\Internet", "Explorer\iexplore.exe", and MyParam1 as parameters.
 
Code:
RunIt = """C:\Program Files\Internet Explorer\iexplore.exe"" " & MyParam1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In VBScript, there are several activities that can lead to the need to produce strings that have double quotes (") embedded in them. Most often this comes about due to the need to run an external command where spaces are present in a path.
So we can use this Function :
Code:
Function qq(strIn)
    qq = Chr(34) & strIn & Chr(34)
End Function
and your example become like that:
Code:
Dim MyParam1
Dim ObjShell
Dim RunIt

If Wscript.Arguments.Count <> 1 Then
    Wscript.echo "Incorrect Parameters.  One required."
Else
    MyParam1 = Wscript.Arguments.Item(0)
    Wscript.Echo "Params: " & MyParam1
End If

Function qq(strIn)
    qq = Chr(34) & strIn & Chr(34)
End Function

Set objShell = CreateObject("WScript.Shell")
RunIt = "C:\Program Files\Internet Explorer\iexplore.exe " & MyParam1
MsgBox qq(RunIt),64,"RunIt"
objshell.Run qq(RunIt)
 
Thanks chaps.

Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top