Calling a VB exe from a batch, and detecting it's success or failure from the batch

I need to call blah.exe from a batch file.  And from this batch file I need to know whether or not blah was succesful.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi JamesSmithIsTaken,
if %errorlevel%==0 then goto end
echo "program failed"

Regards .. Alan
JamesSmithIsTakenAuthor Commented:
Thanks, that's the batch file side of the question.

How do I return the errorlevel from inside the application?

The only way I know to exit the VB application is with End
A simple way is create a file from your batch like this

echo Starting >myfile.txt

And have then VB program kill the file before the end...

Kill "MyFile.txt"

So in your batch file you can test for the file

If Exist MyFile.txt goto SystemCrash
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mike TomlinsonMiddle School Assistant TeacherCommented:
On my system, if file.exe is a VB App, then the batch file returns before the app is finished and/or closed.

Try this

in VB form

Option Explicit
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call ExitProcess(1)
End Sub

in bat file
echo %errorlevel%

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:

I have used that API successfully before and trapped the exit code from other programs without trouble.  However, on my system, just launching the executable from the batch file is seen as success and the batch file continues on with the next line with exit code 0 before the app has actually finished.

Have you tried trapping the code from a batch file on your system?  I am using WinME.

I did try what I posted in Win 2000 Server and it works

If I replace to  Call ExitProcess(100)

I will see 100 from printout

>>the batch file continues on with the next line with exit code 0 before the app has actually finished.

No it wait till the [project1.exe finished
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's what I'm saying...on my system it doesn't.  It immediately returns with 0.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Thanks for the response.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Must be a difference between ME and NT/2000/XP.

What OS do you use?
>>Must be a difference between ME and NT/2000/XP

for sure, they are total different from me and nt/2000/XP professional or higher
JamesSmithIsTakenAuthor Commented:
I teseted on XP.. it works

for some reason the batch file knows to wait for %errorlevel% if you put %userprofile% there instead I think it wouldn't break.

Thanks for the answers guys
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.