?
Solved

How to terminate a running application?

Posted on 2003-03-11
13
Medium Priority
?
312 Views
Last Modified: 2012-05-04
Let me be specific about my question.

After I run a visual basic project, I want to terminate the running application by pressing a Button in a form.

I made the exe file from the project I wrote. After I run the exe file, and after I am done with the application I am closing the application to terminate it. After I close the application in the Windows Task Manager I still see the .exe file in the processes tab (of windows Task Manager) and the name of the running application in the Application tab.

The number of times that I access the exe file, that many number of .exe files are in the Windows task manager(In the processes tab). So I am in a need of terminating each application and .exe by pressing the end task button in the windows task manager.

Basically I need the Visual Basic code which I could put under a Button_click method in a form. So that I could press it to terminate the application without leaving the .exe still running in the windows task manager. If any one knows the solution to this please help me on  this.

Thank you.

regards,
Thas
0
Comment
Question by:thas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8115714
Unload Me
0
 
LVL 3

Accepted Solution

by:
DocM earned 1000 total points
ID: 8115850
Here is code to check that all the forms unload correctly.

Private Sub Form_QueryUnload(CANCEL As Integer, UnloadMode As Integer)
 Dim FRM As Form

   If (CANCEL = 0) Then
       For Each FRM In Forms
           If (FRM.Name <> Me.Name) Then Unload FRM
       Next
       For Each FRM In Forms
           If (FRM.Name <> Me.Name) Then
            CANCEL = 1 ' Do not unload Me.
            MsgBox FRM.Name & ": refused to Unload."
           End If
       Next
   End If
End Sub
0
 

Expert Comment

by:cocomobasic
ID: 8116265
' hi, try this

Private Sub Command1_Click()

    End

End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:SilentRage
ID: 8116282
Here's the dirty way to make sure that the program shuts down no matter what.  Sometimes if you have loops going on, they can reload the form you're trying to close.  You SHOULD fix those kind of bugs, but you can remember this...

Private Sub cmdExit_Click()
   End
End Sub
0
 
LVL 1

Expert Comment

by:SilentRage
ID: 8116284
darnit.  heh, we both posted at the same time.
0
 
LVL 1

Expert Comment

by:irfanazam
ID: 8117025
Hi,

there are number of things to consider in such situation.

1). you may be terminating your application by unloading your form using something like "Unload Me". In this case your current form will be unloaded but if there is some other form of your application is left loaded in memory then your application will not terminated and will be shown in task manager.

2). you may be terminating your application using END. this should terminate application properly without any forms to be left loaded. but some times we still get the same probelm. but chances are very few.

3). If you want to get rid of this situation make sure to unload each form explicitly like this

For Each FRM In Forms
Unload FRM
Next

4). you should always take care of if you access some property of a form or some control on a form and that form is not loaded then in above two situations that form will be loaded into memory. but will not be visible. for example you have 2 forms in your application Form1 and Form2. your Form1 is your main form and is visible but Form2 is not loaded. then if you access some property of Form2 or some control on Form2 then this will also load Form2. and about 80% programmers never take care such things. so the explicit unload as i have mentioned in point 3 saves us from this problem.

Hope you will get my point.
0
 
LVL 1

Expert Comment

by:SilentRage
ID: 8119566
2). you may be terminating your application using END. this should terminate application properly without any forms to be left loaded. but some times we still get the same probelm. but chances are very few.

I disagree.  I've never heard of a program NOT closing immediately when execution hits the End statement.  The only bad thing about End is that it will not execute the Unload events for a form.
0
 
LVL 1

Expert Comment

by:irfanazam
ID: 8125339
But i have encountered some situations when END made my application to crash. Once i was using a third party activex to have a custom menu like XP in VB6 application. whenever i called END in some event of that menu control my application crashed immediately then i explicilty unloaded all forms to terminate my application.
0
 
LVL 1

Expert Comment

by:SilentRage
ID: 8130669
heh heh, yeah, you're right.  I guaranteed the application will end if you use End.  I didn't say that the program won't crash if you don't clean up some things first.  ;)  It might crash, but it WILL end.  :P
0
 

Expert Comment

by:CleanupPing
ID: 8900262
thas:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 1

Expert Comment

by:SilentRage
ID: 9012768
DocM should recieve the points

The method I had tried to post is the dirty method, and, I'm not the only one who posted it.  Shoot, I didn't even manage to post it first.  If nobody had replied, the solution DocM provided would be similar to the code I would've posted.  It isn't fool-proof, but when the asker wanted to do it from the button rather than designing his program better, it is the best of the relevent solutions.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9097153
Thanks for the feedback SilentRage.  Moderator, my recommended disposition is:

    Accept DocM's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question