Click to See Complete Forum and Search --> : Making VB app. return exit code


Kooper Tina
September 15th, 1999, 04:14 PM
I am executing a VB program as a Part of SQL server Job and wants it to return exit code telling its success and failure based on which it can make further decision.

Lothar Haensler
September 16th, 1999, 01:41 AM
if you end your VB program via ExitProcess API you can specify a "return code", that can be trapped by a calling process.

Kooper Tina
September 16th, 1999, 10:24 AM
Thanks a lot Lothar ,You make it sound possible and easy.I am completely trapped into doing this.
Can I request you to explain it a little more.Will the return value of this API cCall EXIT PROCESS serve as exit code?
Thanks in advance

Lothar Haensler
September 16th, 1999, 10:38 AM
Hi Tina,
let's assume your VB app looks like this:

declaration for ExitProcess goes here (from API-Addin)
Sub Main
Call ExitProcess(1)
End Sub

Then, e.g. in an NT Commandfile
yourprogram.exe
if errorlevel 1 goto error
goto ok
:error
program failed
:ok


See what I mean? You can query the argument to ExitProcess in a command file via ERRORLEVEL or in another process via GetExitCodeProcess API.
I am not sure if it is smart to end a VB program with ExitProcess.
It might cause problems with unreleased resources.
If does work, though as far as returning an exit code is concerned.

Lothar Haensler
September 16th, 1999, 11:16 AM
here's a complete sample tested in NT 4

option Explicit
private Declare Sub ExitProcess Lib "kernel32" (byval uExitCode as Long)

Sub Main()
ExitProcess 5
End Sub



Make exe: c:\project1.exe
the command file
@echo off
c:\project1.exe
if errorlevel 5 goto error
goto ok
:error
@echo error
:ok

play around with the exitprocess statement: set it's argument to 5 or zero and see what happens in the commandfile!