Re: basic help to run an application from WSH

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks Richard and Tom, nowhere did I find as clear an explanation as
you guys just gave me. Thank you!


Richard Mueller wrote:
Hi.

The Run method requires at least one argument, which is a string. The value
of the string is the path and filename of a program to be executed. All
string values must be enclosed in quotes. If a path and filename has spaces,
the value must be enclosed in quotes. Any embedded quotes in a quoted string
must be doubled. For example:

WshShell.Run "c:\notepad.exe"

will work. The Run method will execute on c:\notepad.exe. However:

WshShell.Run "c:\My Folder\notepad.exe"

will not work, because c:\My Folder\notepad.exe is not understood. You want
the run method to execute "c:\My Folder\notepad.exe". So, to pass the
embedded quotes, you must double them. This will work:

WshShell.Run """c:\My Folder\notepad.exe"""

The WSH interpreter resolves the embedded double quotes into single quotes
and passes the following to the Run method:

"c:\My Folder\notepad.exe"

which is a valid statement to execute.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
<georgeoliverGO@xxxxxxxxx> wrote in message
news:1160491239.242671.123500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OK, I found that enclosing the file path in -three- sets of quotation
marks, such as

"""<file path"""

works.

What I don't understand is why you need three sets, any help?

(I suppose I didn't look everywhere, then...)


georgeoliverGO@xxxxxxxxx wrote:
hello,

Apologies for such a basic question, but I've looked everywhere and
nothing is helping.

I'm just learning vbscript for wsh and here is my first script, saved
in file "<file>.vbs":

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "<file path of file.vbs>"

Where <...> is a full file path such as "c:\documents and
settings\[...]" etc.

When I run this by selecting the file I always get a

Script: <script file path>
Line: 2
Char: 1
Error: THe system cannot find the file specified.

Code: 80070002
Source: (null)


However if I just move the file to c:\, so the path is "c:\<file>" the
file opens.

Also if I cut and paste the exact file path from the script into the
Run box on the start menu, the file opens.

Any help with this?

Many thanks.


.



Relevant Pages

  • Re: Launching Multiple Programs From A Command Prompt Script
    ... quotes "" before the quotes containing the actual executable name, ... >> I would like to launch multiple programs from a command prompt script ... the script will not execute the second line until the first ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: basic help to run an application from WSH
    ... The Run method requires at least one argument, which is a string. ... string values must be enclosed in quotes. ... The Run method will execute on c:\notepad.exe. ... I'm just learning vbscript for wsh and here is my first script, ...
    (microsoft.public.scripting.vbscript)
  • Re: [PHP] Not Null?
    ... I have a script that looks for the variable to be NULL and then execute.. ... Steve, use regular single or double quotes, not any kind of fancy ... Microsoft Word or another similar word processor, ...
    (php.general)
  • Applescript and Autoformat (search and replace), Word 2004
    ... script that will take care of a recurring editing issue with nested ... quotes to double quotes, ... set oldauto2 to auto format as you type replace quotes ... set auto format as you type replace quotes to false ...
    (microsoft.public.mac.office.word)
  • Re: Accessing full command line or parameters WITH QUOTES
    ... The problem is that VBScript doesn't allow access to the full command line ... rebuild the parameters with the quotes inserted properly. ... When I was writing the script on XP, I managed to cheat and grab the ...
    (microsoft.public.scripting.vbscript)