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

wscript.shell Run file with space in path

20,421 views
Skip to first unread message

req...@gmail.com

unread,
Mar 11, 2008, 10:35:09 AM3/11/08
to
I'm trying to run the following, but I always receive an error due to
the space between Program Files. I've tried quoting it in standard
style and in ascii but then the file cannot be found. The file is at
the path specified. Anyone see the error?

Set WSHShell = CreateObject("Wscript.Shell")
return = WSHShell.run ("C:\Program Files\7-Zip\7z.exe e C:\ziptest
\test.zip -y -oc:\ziptest *.txt -r",1,true)

ekkehard.horner

unread,
Mar 11, 2008, 10:41:41 AM3/11/08
to
req...@gmail.com schrieb:
One method to get " into a literal string is to 'escape it' the VBScript
way: use "" (where you would use \" in C/C++).

return = WSHShell.run( """C:\Program Files\7-Zip\7z.exe"" e ...


req...@gmail.com

unread,
Mar 11, 2008, 10:54:59 AM3/11/08
to
On Mar 11, 9:41 am, "ekkehard.horner" <ekkehard.hor...@arcor.de>
wrote:
> requ...@gmail.com schrieb:> I'm trying to run the following, but I always receive an error due to

I'm still receiving the error that the file cannot be found. I'm
tyring:

ekkehard.horner

unread,
Mar 11, 2008, 11:06:10 AM3/11/08
to
req...@gmail.com schrieb:

return = WSHShell.run( """C:\Program Files\7-Zip\7z.exe"" e C:\ziptest\test.zip


-y -oc:\ziptest *.txt -r",1,true)

One line; the full path has to be quoted. You would make it easier for yourself
if you'd store the command into a variable and WScript.Echo it to check/compare
against a working command line.


Corey Thomas - MCSE/MCSA/MCDBA

unread,
Mar 11, 2008, 12:15:00 PM3/11/08
to
Corrected your code below. The double quotes are needed on the entire string
since it has whitespace:

Set WSHShell = CreateObject("Wscript.Shell")
return = WSHShell.run ("""C:\Program Files\7-Zip\7z.exe e
C:\ziptest\test.zip -y -oc:\ziptest *.txt -r""",1,true)


-Corey

Pegasus (MVP)

unread,
Mar 11, 2008, 1:03:01 PM3/11/08
to
If you follow Ekkehard's recommendation and turn the command
into a string then you will see immediately that your code cannot
possibly work:

Set WSHShell = CreateObject("Wscript.Shell")

wscript.echo """C:\Program Files\7-Zip\7z.exe e

C:\ziptest\test.zip -y -oc:\ziptest *.txt -r"""


"Corey Thomas - MCSE/MCSA/MCDBA"
<CoreyThomasM...@discussions.microsoft.com> wrote in message
news:71724248-2EB9-481C...@microsoft.com...

ekkehard.horner

unread,
Mar 11, 2008, 1:48:59 PM3/11/08
to
Pegasus (MVP) schrieb:

> If you follow Ekkehard's recommendation and turn the command
> into a string then you will see immediately that your code cannot
> possibly work:
>
> Set WSHShell = CreateObject("Wscript.Shell")
> wscript.echo """C:\Program Files\7-Zip\7z.exe e
> C:\ziptest\test.zip -y -oc:\ziptest *.txt -r"""
>
>
> "Corey Thomas - MCSE/MCSA/MCDBA"
> <CoreyThomasM...@discussions.microsoft.com> wrote in message
> news:71724248-2EB9-481C...@microsoft.com...
>> Corrected your code below. The double quotes are needed on the entire
>> string
>> since it has whitespace:
>>
>> Set WSHShell = CreateObject("Wscript.Shell")
>> return = WSHShell.run ("""C:\Program Files\7-Zip\7z.exe e
>> C:\ziptest\test.zip -y -oc:\ziptest *.txt -r""",1,true)
[...]
It won't work, if the whole command line (pathes and options)
is enclosed in " (written as ""), but putting the " where they
are needed (the full file spec for 7z.exe) should be correct.

aceqbaceq

unread,
May 11, 2008, 2:09:58 PM5/11/08
to
i did:

"C:\Program Files\7-Zip\7z.exe e C:\temp\4\7-Zip.7z -y -oc:\temp\4\ *.txt -r"

and i did:

Set shep = WScript.CreateObject("WScript.Shell")
shep.Run """C:\Program Files\7-Zip\7z.exe"" e C:\temp\4\7-Zip.7z -y -oc:\temp\4\ *.txt -r"

and in both cases all worked great :).

if in wsh script we have file paths with "spaces" then we need to embrace those paths with- ""file path"".

in my case it is ""C:\Program Files\7-Zip\7z.exe""
hope this will help :)

nanc...@gmail.com

unread,
Sep 11, 2014, 3:48:48 AM9/11/14
to
Dim WshShell

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\abc_edf\cde\qw.exe""",1,true
set WshShell = Nothing


I am still getting "the system cannot find the file specified.
it is because of spaces.
I tried using double quotes as well.

Please help

Evertjan.

unread,
Sep 11, 2014, 4:20:43 AM9/11/14
to
nanc...@gmail.com wrote on 11 sep 2014 in
microsoft.public.scripting.vbscript:

> Dim WshShell
>
> Set WshShell = CreateObject("WScript.Shell")
> WshShell.Run """C:\Program Files\abc_edf\cde\qw.exe""",1,true
> set WshShell = Nothing

I don't thing the tripple quote will help you.

> I am still getting "the system cannot find the file specified.

ok

> it is because of spaces.

Why do you think that, what is the error you get?

Try a string that does not contain the _
perhaps the _ is a stand-in for a space?


> I tried using double quotes as well.

Please quote what you are replying on,
this is usenet, not Google groups or email.

Read:

Run Method (Windows Script Host)
<http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx>



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

nanc...@gmail.com

unread,
Sep 11, 2014, 4:33:16 AM9/11/14
to
no the underscore is not the space . it is name of folder.

nanc...@gmail.com

unread,
Sep 11, 2014, 5:09:06 AM9/11/14
to
The error is due to folder name contains underscore. can anyone help what shall be done?

R.Wieser

unread,
Sep 11, 2014, 6:13:29 AM9/11/14
to
Nancy,

> The error is due to folder name contains underscore.

I don't think so. An underscore is a quite normal character that may be
used in folder as well as filenames, just as most other characters.

1) Have you tried creating such a foldername yourself, and see if it fails
too (copy use something like "notepad.exe" into the folder for the
executable) ? If not ... :-)

2) Have you tried to run the script in the "cde" folder (using
"""cde\qw.exe""") ? Maybe the program itself refuses to run.

Next, try accessing that folder from within a DOS- or CMD-box and see if you
can DIR and/or CD on that "abc_edf" folder. If that does not work the
underscore may be a viewing-only replacement of an undisplayable character
(read: the foldername itself has been damaged).

And that would mean you've got a problem: You could rename the folder, but
that could mean the "gw.exe" program could fail to work properly (it expects
a path that does not exist anymore). The only thing to do than is to
un-install and re-install the program again, assuming that that will replace
the damaged foldername.

Regards,
Rudy Wieser


-- Origional message
<nanc...@gmail.com> schreef in berichtnieuws
c94d7c46-cbdb-4304...@googlegroups.com...

Dave "Crash" Dummy

unread,
Sep 11, 2014, 7:09:40 AM9/11/14
to
This thread is so screwed up I'm not sure where to respond. Use the
"exec" method, not the "run" method, and get out of Google.

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("C:\Program Files\abc_edf\cde\qw.exe")
set WshShell = Nothing

See the VBScript manual for details on the "exec" method.

--
Crash

"The future ain't what it used to be."
~ Yogi Berra ~

GS

unread,
Sep 11, 2014, 7:27:35 AM9/11/14
to
> The error is due to folder name contains underscore. can anyone help
> what shall be done?

Both these work for me...

Set oSH = CreateObject("WScript.Shell")
oSH.Run """C:\Program Files\Textpad_7\Textpad.exe"""
Set oSH = Nothing

Set oSH = CreateObject("WScript.Shell")
oSH.Run """C:\Program Files\Textpad 7\Textpad.exe"""
Set oSH = Nothing

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


GS

unread,
Sep 11, 2014, 7:35:39 AM9/11/14
to
The 'exec' method has a different purpose than the 'run' method! The
'run' method is the correct choice here and works just fine...

Todd Vargo

unread,
Sep 11, 2014, 12:22:48 PM9/11/14
to
Why did you add "SOLVED" to the subject line? That is very confusing.

Please confirm that "C:\Program Files\abc_edf\cde\qw.exe" leads to an
actual executable file. In other words, the abc_edf folder appears to be
a made up folder name in code only that does not actually exist.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Mayayana

unread,
Sep 11, 2014, 12:49:54 PM9/11/14
to
| This thread is so screwed up I'm
| not sure where to respond.

I'm guessing that nancya85 is Google's
latest foray into the field of AI. They're
testing it on us. The first test is to see
if it will pass for human in a newsgroup.
If that works out then they try having it
play online chess. :)



Dave "Crash" Dummy

unread,
Sep 11, 2014, 2:28:15 PM9/11/14
to
I want to see it up against Watson on Jeopardy.
--
Crash

Committed to the search for intraterrestrial intelligence.
0 new messages