Solved

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

Posted on 2003-12-05
13
624 Views
Last Modified: 2011-04-14
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.

Thanks
0
Comment
Question by:JamesSmithIsTaken
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 10

Expert Comment

by:ADSaunders
ID: 9882930
Hi JamesSmithIsTaken,
file.exe
if %errorlevel%==0 then goto end
echo "program failed"
:end

Regards .. Alan
0
 
LVL 1

Author Comment

by:JamesSmithIsTaken
ID: 9883055
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
0
 
LVL 17

Expert Comment

by:inthedark
ID: 9883169
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883225
On my system, if file.exe is a VB App, then the batch file returns before the app is finished and/or closed.

Idle_Mind
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 200 total points
ID: 9883267
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
c:\temp\project1.exe
echo %errorlevel%
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883348
EDDYKT,

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.

Idle_Mind
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 9883627
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883869
That's what I'm saying...on my system it doesn't.  It immediately returns with 0.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883871
Thanks for the response.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883890
Must be a difference between ME and NT/2000/XP.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9883909
James

What OS do you use?
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9883918
>>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
0
 
LVL 1

Author Comment

by:JamesSmithIsTaken
ID: 9886323
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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now