Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WshShell.Run: Spaces in variable

883 views
Skip to first unread message

Florian Dietz

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
What I am trying to do is to start a programme, the name of which the
'.vbs'-script gets by a command line parameter:

call of the script, e.g.:
script.vbs "C:\Programme\Microsoft Reference\Bookshelf 96\bshelf96.exe"

Thereafter I get the name and path of the executable by:
Set objArgs = Wscript.Arguments
programmeName = objArgs(0)

Finally I try to run the executable by:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run(programmeName)

WSH won't find the programme named programmeName because of the spaces
in the path. Even a call with more double-quotes as
script.vbs """C:\Programme\Microsoft Reference\Bookshelf
96\bshelf96.exe"""
won't work.

The line
WshShell.Run(""" & programmeName & """)
didn't help either.

So, how can I call an executable by variable with spaces in the name?

Florian Dietz

lpge...@my-dejanews.com

unread,
Aug 10, 1998, 3:00:00 AM8/10/98
to
I got around the embedded space problem by inserting dbl quotes before and
after the string. This following is a small vb example that seems to work ok.

Dim obj As Object
Dim FileName

Set obj = CreateObject("WScript.Shell")
FileName = "C:\Program Files\Accessories\Msaint.exe"
FileName = Chr(34) & FileName & Chr(34)
obj.Run FileName

hope this helps?

In article <35C9BC17...@irt.rwth-aachen.de>,


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

Florian Dietz

unread,
Aug 11, 1998, 3:00:00 AM8/11/98
to
Florian Dietz wrote:
>
> ...

> The line
> WshShell.Run(""" & programmeName & """)
> didn't help either.
>
> So, how can I call an executable by variable with spaces in the name?
>
> Florian Dietz

I solved the problem by putting 4 (four!) double-quotes in the line:


WshShell.Run("""" & programmeName & """")

The first one is to mark the beginning of the string, the second and
third double-quotes stand for one double-quote contained in a string,
and finally, the fourth to close the string.

Florian

0 new messages