Get the exitcode of a called application.

Posted on 2006-05-31
Last Modified: 2010-04-01
Hi, I am trying to run an application and get its exitcode.  How would I go about doing this?
Question by:List244
    LVL 86

    Accepted Solution

    Just use 'GetExitCodeProcess()', e.g. like in

    DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd)
       STARTUPINFO         si;

       BOOL                bRes;

       DWORD               dwCode  =   0;

       ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

       si.cb           =   sizeof  (   STARTUPINFO);
       si.dwFlags      =   STARTF_USESHOWWINDOW;
       si.wShowWindow  =   SW_SHOWNORMAL;

       bRes    =   CreateProcess   (   NULL,

       while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                   while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                               DispatchMessage     (   &msg);

       GetExitCodeProcess  (   pi.hProcess,    &dwCode);

       CloseHandle (   pi.hProcess);
       CloseHandle (   pi.hThread);

       return  (   dwCode);
    LVL 8

    Author Comment

    That works.
    LVL 86

    Expert Comment

    ... for years now *duck* ;o)

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now