Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-12-05
13
Medium Priority
?
639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

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 800 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 86

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
 
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 86

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 86

Expert Comment

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
Suggested Courses

610 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