CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 1999
    Posts
    2

    Making VB app. return exit code

    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.


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Making VB app. return exit code

    if you end your VB program via ExitProcess API you can specify a "return code", that can be trapped by a calling process.


  3. #3
    Join Date
    Sep 1999
    Posts
    2

    Re: Making VB app. return exit code

    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



  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: Making VB app. return exit code

    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
    k


    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.


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: Making VB app. return exit code

    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
    k

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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured