Avatar of ccampbell15
ccampbell15 asked on

WshShell.Run doesn't wait

Hi all,

I reduced things to a very simple test case because I just can't get WshShell.Run  to wait until the cmd file it calls to complete.

test.vbs
Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run ("C:\hello.cmd", 2,TRUE)


hello.cmd
echo hello
pause

I was expecting the test.vbs to open the cmd file minimized and remain open until I hit the enter key in the cmd window.

According to http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
that should work.

Can somone move one of the trees so I can see the forest please?

Regards
Lee
Shell ScriptingVB Script

Avatar of undefined
Last Comment
Gerwin Jansen

8/22/2022 - Mon
SOLUTION
Gerwin Jansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Bill Prew

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
ccampbell15

I created yet another cmd file that calls the vbs like cscript //nologo test.vbs.  The vbs then calls the script I want to run but still does not wait.

The test.vbs is actually a larger script that is part of an installer package.  Using an app from Xneat I convert the .vbs to a .exe so I can run it and wait on that file to complete before moving on.

So far I can’t get the WaitOnReturn to actually wait.  


cmd /c  makes no difference.  The cms file is doing what it's supposed to the WaitOnReturn  inside of the vbs is not
Gerwin Jansen

What I'm suggesting (and tested) is that test.vbs contains:

Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run ("cmd /c C:\temp\hello.cmd", 2,TRUE)

and that hello.cmd contains:

echo hello
pause

If I run test.vbs from a cmd prompt (on c:\temp), I get a new cmd prompt that is displaying:

C:\Temp>echo hello
hello

C:\Temp>pause
Press any key to continue . . .

Did you try that / does it work for you?
Bill Prew

So are you testing the vbs script or are you testing the converted exe version of it?

What version of Windows?

~bp
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
ccampbell15

I'm tested both the exe and the vbs.  I created a .cmd that called the .vbs using cscript and also tried the .exe

The cmd file itself does indeed wait until I enter the enter key.  The problem is that the vbs does not wait.  It fied off the cmd and just went on it merry way
ASKER
ccampbell15

Oh forgot,

Win7 Pro
Bill Prew

Well, this is quite strange. I am on 32 bit Win 7 Pro as well, and am doing exactly what you are doing, and the vbscript doesn't exit until after I press enter in the new command window.

~bp
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Bill Prew

Try changing your RUN to this, and see if it waits until you exit notepad or not (it does here).

return = WshShell.Run ("notepad", 2,TRUE)

~bp
ASKER
ccampbell15

Oh Geez,

I had 2 folders with the same filenames.  Edit the file in one folder but running the other - DUH!
Sorry guys.
Gerwin Jansen

No problem at all, glad you've found it ;)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck