Closing an external program programmatically
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Closing an external program programmatically

  1. #1
    Join Date
    Oct 2002
    Posts
    70

    Closing an external program programmatically

    I want to be able to make an external program exit from my code.

    I start the process for the executable, then I want to do something within my program. Then once that is done I want to close the external program.

    My code at present:-

    // Start the child process.
    if( !CreateProcess( NULL, // No module name (use command line).
    "PleaseWait.exe", // Command line.
    NULL, // Process handle not inheritable.
    NULL, // Thread handle not inheritable.
    FALSE, // Set handle inheritance to FALSE.
    0, // No creation flags.
    NULL, // Use parent's environment block.
    NULL, // Use parent's starting directory.
    &si, // Pointer to STARTUPINFO structure.
    &pi ) // Pointer to PROCESS_INFORMATION structure.
    )
    {
    AfxMessageBox( "CreateProcess failed." );
    }

    // Would normally do this but I want to control when it exits
    //WaitForSingleObject( pi.hProcess, INFINITE );

    :::

    // DO SOMETHING HERE

    :::
    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

    Any ideas?

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Take a look at this FAQ...
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center