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.
Printable View
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.
if you end your VB program via ExitProcess API you can specify a "return code", that can be trapped by a calling process.
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
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.
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!