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

    Detect when another program closes

    I want to be able to detect when another program exits. For example, if i exit my browser, i want my program to detect this and launch another process. How do i do this?

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Detect when another program closes

    If you are the one who start the process, you have the Process instance and you can wait for its exit. Otherwise (but there definitelly must be a better solution) you could periodically check the list of running process and if the one which you are interested in is there any more, you can suppose that it has finished.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Detect when another program closes

    If the application is not launched from your own program then another way would be to hook into the application in question here and trap WM_CLOSE message, but that would require good understanding of APIs.

  4. #4
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Detect when another program closes

    Quote Originally Posted by Shuja Ali View Post
    If the application is not launched from your own program then another way would be to hook into the application in question here and trap WM_CLOSE message, but that would require good understanding of APIs.
    oh yes, I've tried it once ;] and I managed to crash or hang Vista many many times
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Detect when another program closes

    I think you could use the PeekMessage or GetMessage APIs to determine the WM_CLOSE event, it is a bit tricky though...
    I'd also periodically loop through all running processes to determine this.

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