CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Exclamation Endtask Application...

    Is there any way to avoid my application getting killed through task manager... or a way to detect that task manager is going to terminate the application....

  2. #2
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: Endtask Application...

    I think that task manger can kill your application in any case... The only things that I can think to avoid this is to make tm believe your is a system critical task; in that case it would refuse to terminate the task.

    But why you want to exert such a control over the user? I think this violates programming ethics...

    To detect if your application is about to be terminated normally there are ways, like override virtual function ExitInstance in your CWinApp derived class, or handling the message WM_CLOSE in the MainFrame or other fundamental window of the app, but I don't know exactly if these method works also with task manager termination, that follows not the regular terminating way, but a brute force approach...

    I delegate this to more expert people in this forum
    - Buzzyous -

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Endtask Application...

    Quote Originally Posted by LOOSER_007 View Post
    Is there any way to avoid my application getting killed through task manager... or a way to detect that task manager is going to terminate the application....
    Why would you like to do that? That sounds like some malicious application.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jan 2009
    Posts
    14

    Re: Endtask Application...

    Yes but why do you need to it?

  5. #5
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Re: Endtask Application...

    Actually in my application m communicating with some drivers thus before killing the application i want to store some info(into a file or reg) so that i can restore the info on next relaunch of the application....

  6. #6
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Endtask Application...

    There can be many legitimate reasons to be notified before the app closes - even by task manager, and here's one basic approach (it won't catch all possible ways, but nearly all).

    Handle the WM_CLOSE message in your frame window. That message is sent when the user clicks the X in the top right of the app, or when they use Alt-F4, or from the Task Manager (applications tab) when they choose End Task.

    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Endtask Application...

    Quote Originally Posted by LOOSER_007 View Post
    Actually in my application m communicating with some drivers thus before killing the application i want to store some info(into a file or reg) so that i can restore the info on next relaunch of the application....
    So put that in the normal shutdown code. If the use chooses to terminate your app through task manager, that's their prerogative and more than likely they'd have a good reason for it.

    If it were my computer, any program I found that was making a deliberate attempt to hide or subvert my control would be removed immediately. That's just not how legitimate programmers write code. You should stop thinking like that immediately or find another board to ask those questions on.

  8. #8
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Endtask Application...

    Quote Originally Posted by GCDEF View Post
    If it were my computer, any program I found that was making a deliberate attempt to hide or subvert my control would be removed immediately. That's just not how legitimate programmers write code.
    While I agree that any attempt to hide or subvert your control is not a good thing, I would not say that a legitimate intercept of a task manager shutdown request is "not how a legitimate programmer" would write code.

    Several of our applications process very large amounts of data - sometimes requiring more than 20 hours to process. By catching the WM_CLOSE (which catches the X button and also a shutdown request from task manager), we can warn the user through a pop-up that the processing is incomplete and they need to stop the processing before closing - but then we also provide a Cancel button to gracefully shut down the processing.

    In any event, if you handle the WM_CLOSE for your purpose, you should warn the user, and give them the option to gracefully shutdown by executing your cleanup code, or to ignore the shutdown request.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

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