Solved

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

Posted on 2003-12-05
13
627 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 64
Excel object stays open 19 71
Updates not working for MS Windows 7 12 152
Visual Studio 2005 text editor 10 35
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

17 Experts available now in Live!

Get 1:1 Help Now