PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Detect when program is terminated-VBForums
Results 1 to 20 of 20

Thread: Detect when program is terminated

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Detect when program is terminated

    hi everyone, i'm here again, needing your help.
    i just want to know if there is a way fo me to detect when my application is terminated??? because if my application is terminated from the process tab in task manager, form_unload is not fired can this be done using subclassing or through windows hook? hope you guys can help me.

  2. #2
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Detect when program is terminated

    Hang on, if your program is terminated, it would not be around to react tot he termination. Or is there a way of catching it before it terminates?
    My Flickr Stream


    My Sites Blog Twitter Flickr

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Detect when program is terminated

    There is an Unload mode in the QueryUnload event that should capture how the program was terminated. Here are the unload modes. Try them out.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2. 'there are 5 unloadmode levels
    3.         Select Case UnloadMode
    4.             Case vbFormControlMenu 'UnloadMode 0
    5.                  'form is being unloaded via the Close
    6.                  'or by hitting the X in the upper right hand corner
    7.                  'command from the System menu
    8.             Case vbFormCode        'UnloadMode 1
    9.                  'Unload Me has been issued from code
    10.             Case vbAppWindows      'UnloadMode 2
    11.                  'Windows itself is closing
    12.             Case vbAppTaskManager  'UnloadMode 3
    13.                  'the Task Manager is closing the app
    14.             Case vbFormMDIForm     'UnloadMod 4
    15.                  'an MDI child form is closing because
    16.                  'its parent form is closing
    17.         End Select
    18. End Sub
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Detect when program is terminated

    it doesn't have to be my own program who will ddetect/react from that event, i could use another program for that.

    i don't think the Form_QueryUnload will be fired when you terminate your app using "End Process" from the task manager

    i think this can be done using subclassing, i know there must be a windows message for this... i just don't know yet

  5. #5
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Detect when program is terminated

    Quote Originally Posted by guyjasper
    i don't think the Form_QueryUnload will be fired when you terminate your app using "End Process" from the task manager
    Oh yes it will, and if you want an example, I would be more than happy to attach one (I just created a exe with a msgbox in the QueryUnload event, compiled it, ran it, shut it down via Task Manager, and the instant I clicked End Process my messagebox popped up!)

    You can do this with your program, but not someone elses as you can't rewrite the source to look for shutdown methods.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: Detect when program is terminated

    can you please attach a code example because I tested out what you said because I was interested. But it didn't seem to work. I initially thought that a message box wouldn't show because the app is being terminated, so I did a file write test but it didn't work either.

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.   Open "C:\Test.txt" For Output As #1
    3.     Print #1, UnloadMode
    4.   Close #1
    5.  
    6.   MsgBox UnloadMOde
    7. End Sub
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  7. #7
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: Detect when program is terminated

    OH, and to the post starter:

    You can make another app which continues to check if an EXE is running on an API timer. There's tons of code on this forum for checking if an EXE is running.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  8. #8
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Detect when program is terminated

    Quote Originally Posted by VIP3R
    can you please attach a code example because I tested out what you said because I was interested. But it didn't seem to work. I initially thought that a message box wouldn't show because the app is being terminated, so I did a file write test but it didn't work either.

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.   Open "C:\Test.txt" For Output As #1
    3.     Print #1, UnloadMode
    4.   Close #1
    5.  
    6.   MsgBox UnloadMOde
    7. End Sub
    You have to test for the UnloadMode
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2. Open "C:\Test.txt" For Output As #1    
    3.          Select Case UnloadMode    
    4.             Case vbFormControlMenu 'UnloadMode 0
    5.                  'form is being unloaded via the Close
    6.                  'or by hitting the X in the upper right hand corner
    7.                  Print #1, "Close by System Menu or X Button"
    8.                  'command from the System menu
    9.             Case vbFormCode        'UnloadMode 1
    10.                  'Unload Me has been issued from code
    11.                  Print #1, "Closed by programming code"
    12.             Case vbAppWindows      'UnloadMode 2
    13.                  'Windows itself is closing
    14.                  Print #1, "Closed because Windows is shutting down"
    15.             Case vbAppTaskManager  'UnloadMode 3
    16.                  'the Task Manager is closing the app
    17.                  Print #1, "Closed By TaskManager"
    18.             Case vbFormMDIForm     'UnloadMod 4
    19.                  'an MDI child form is closing because
    20.                  'its parent form is closing
    21.                  Print #1, "MDI Child closing because Parent is closing"
    22.         End Select
    23. Close #1
    24. End Sub
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  9. #9
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Detect when program is terminated

    Hey Hack,

    I tried this out and it's not working for me, though i might be doing something wrong.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  10. #10
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Detect when program is terminated

    Quote Originally Posted by space_monkey
    Hey Hack,

    I tried this out and it's not working for me, though i might be doing something wrong.
    Did you compile it before testing it? It needs to run from an .Exe

    If you did so, and it still doesn't work, then I will attachment my test program (minus the .Exe which you can compile)
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  11. #11
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Detect when program is terminated

    Yeah i compiled it when i tried it out.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  12. #12
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Detect when program is terminated

    Here is what I used, and it worked just fine and dandy on my machine. I've also enclosed the text file it wrote.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  13. #13
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Detect when program is terminated

    This is so odd. It's still doesn't seem to be working. If i step through and just close by clicking the "X", it works just fine, but it's not even generating a text file when i close with task manager.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  14. #14
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Detect when program is terminated

    Hang on. I figured out what i was doing wrong. I was clicking on "End Process". Instead of "End Task". It works fine for "End Task".


    sorry
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  15. #15
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Detect when program is terminated

    Quote Originally Posted by space_monkey
    Hang on. I figured out what i was doing wrong. I was clicking on "End Process". Instead of "End Task". It works fine for "End Task".


    sorry
    Right, End Process is the same as using End in your app. Nothing fires after that has been issued.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  16. #16
    March 2015 Winner kfcSmitty's Avatar
    Join Date
    May 2005
    Location
    Kingston, Ontario
    Posts
    2,153

    Re: Detect when program is terminated

    Just a note I want to add in...He was saying it wont work with "End Process", not "End Task"

  17. #17
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Detect when program is terminated

    I think that was why i got cofused.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Detect when program is terminated

    yes, that was what i meant. so i guess this is impossible to trap from your own application if it is the one being terminated through "End Process". can i then use subclassing or windows hooks? it would be great if someone knows how. i think using subclassing or hooks is better than having a timer that would constantly check if an application has been terminated at specified interval. actually, what i really want to achieved is to have another application that would just sit in the background and notifies me if an application or process has been started or terminated.

    what do you think guys? anyways, thanks for the replies ....

  19. #19
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,000

    Re: Detect when program is terminated

    Just an idea, what if you will use a timer then set a time value in the registry maybe every minute? I think somebody else here also wanted to do what you want but to no avail...

    Take a look at this.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Detect when program is terminated

    if there's no other way then maybe you can have a timer that checks for running process at specified intervals. but it would be better using subclassing or hooking if its possible, this way, you can react immediately. i hope somebody knows how. i've checked that link, doesn't seem to be resolved also i posted a similar topic about it before and it wasn't resolved too

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width