Results 1 to 9 of 9

Thread: program must kill itself

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    52

    program must kill itself

    Hi Everyone -

    I have a program that simply will not die -

    Is there a way to force an application to terminate itself?

    the terminate part of the code is being called -
    but it will not remove itself from memory...

    vb6

    thanks
    tony

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    End?

    This is not a good answer, but it is fairly final.

    Can you be more specific about what is happening? Perhaps you have to clear a bunch of objects.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    52
    Sorry to be so vague -

    I created a module to kill a running application by its
    process ID - and it seems to work...

    the caller program will simply need to call
    a exposed sub and the process will die.

    thanks
    tony

  4. #4
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Can you be more specific , like the Hiker asked.
    Your question is incomplete.

    Are you trying to delete the program from the drive.
    Or are you trying to stop the program from running ??

    The first can't be done from itself, another program is needed herefore.

    The second can be made difficult if not all objects are cleared, and or forms are unloaded. Hiding a form doesn't unload it, it stay's in the background.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    52
    Hi Everyone -

    Since my question didn't seem to obvious....

    i will ask it again - this time in an area of the message
    i am sure will be visible.....

    '*********************************************
    '* Question begins here

    Is there a way to force an application to terminate itself?

    '* Question ends here
    '*********************************************


    I have looped through all the forms -
    setting each one to nothing,
    and applied a unload to each one.

    I'm not entirely sure on the process of destroying (setting to nothing) any and all objects that were created in the program...
    perhaps someone could enlighten me on the looping through
    all the created objects for a particular application??????


    thanks for the replies!!

    take care
    tony

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    If this is a fairly simple program you are talking about, destroying all the forms should be pretty good. If there are other objects that need to be destroyed, you'd probably know about them, because you probably created them. Database connections and database related objects are probably the most common.

    The End statement terminates a program, but you would find that most people on this forum would prefer something a bit nicer than that.

    There may also be an API solution by posting a WM_QUIT message to the program, but you may not need that. In the normal VB6 template program, once you have unloaded all forms, the program quits. In your case, that might not happen. If you don't think you have any other objects, you might just try End.
    My usual boring signature: Nothing

  7. #7
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     'unload only forms
    3.     'unload form2
    4.     'set form2 = nothing
    5.     Set Form1 = Nothing
    6.     End
    7. End Sub
    8.  
    9. Private Sub mnuQuit_Click()
    10.     Unload Me
    11. End Sub
    12.  
    13. Private Sub Command1_Click()
    14.     Unload Me
    15. End Sub

  8. #8
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Surely you need to unload the objects too?
    VB Code:
    1. Function vbCloseForms()
    2. Dim frm As Form
    3. Dim obj As Object
    4.  
    5. For Each frm In Forms
    6.  
    7.     For Each obj In frm
    8.         On Error Resume Next
    9.         Unload obj
    10.     '    Debug.Print obj.Name
    11.         Set obj = Nothing
    12.     Next
    13.     'Calls the Form_Unload Event
    14.     Unload frm
    15.     Set frm = Nothing
    16.  
    17. Next

  9. #9
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Originally posted by swatty
    ...

    Are you trying to delete the program from the drive.
    Or are you trying to stop the program from running ??

    The first can't be done from itself, another program is needed herefore.

    ...
    You CAN do it from within the program, by creating and shelling a batch file.


    TerminateProcess might be useful API

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