Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use code to close a program

Status
Not open for further replies.

sasa888

Programmer
Oct 15, 2001
131
0
0
US
Hi all, is there a way to use vb code to close a program? Just like when you press ctrl+alt+delete? Please help...
 
As with most cases, you can find you answer with API calls. Try the DestroyWindow() api, and I believe there is an end process API. You may have to call a few other APIs to get the handle (hwnd) of a window like FindWindow() or WindowFromPoint(). There is no built in VB function to close another program from code, you have to make api calls.
 
This Code Works for me when I want to close the program I am in.

Sub CloseProgram
Dim I As Integer, j As Integer
j = Forms.Count - 1
For I = j To 0 Step -1
Unload Forms(I)
Next
End Sub
 
Thank you for your tips. What about if I want to close previous instance of this program? For instance, the program is terminated by error, and when you press ctrl+alt+del, you will see the previous instance of the same program..can you use this to close it?
 
End

That's a short answer isn't it. Why would another instance necessarily have the same error? Peter Meachem
peter@accuflight.com
 
I think I need some clarification here. Do you want to know how to close applications that you've created or are you talking about closing any app that may be open, like msWord, Outlook, etc?

Josh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top