Solved

Closing Program

Posted on 2003-11-26
4
586 Views
Last Modified: 2010-05-01
I'm making a program and I want it to shutdown AOL Instant Messenger automatically when it runs. How do I do this ?

Please Help A.S.A.P
0
Comment
Question by:pugandjody
4 Comments
 
LVL 5

Expert Comment

by:juliancrawford
ID: 9827506
You can use FindWindow() API and then CloseWindow() api:

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long) As Long

To use FindWindow you need to know the window class name.  If you don't know what the class name is you can use GetNextWindow() and GetWindowText() to check the open windows until you find the one you need.  Once you get the hWnd of the window, simply use

Call CloseWindow(hWnd) to terminate that application.
0
 

Author Comment

by:pugandjody
ID: 9827585
Ok, that seems like it will work, but I don't know how to to that because i'm fairly new at VB. So could you show me the code to do it ?
0
 

Accepted Solution

by:
eclipse707 earned 50 total points
ID: 9828243
The following link should help you.  They explain how to what you are asking so that you can learn and remember it :-)

http://www.freevbcode.com/ShowCode.Asp?ID=935

Let me know if you need any help with it.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9828365
If the window has a caption you can use SendMessage API. Here is a basic example of killing Notepad opened with a blank document.Just paste this onto a form with a command button:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_CLOSE = &H10


Private Sub Command1_Click()
Dim Hnd As Long
' Find the window by its caption
Hnd = FindWindow(vbNullString, "Untitled - Notepad")
If Hnd = 0 Then Exit Sub
' send close message to window
SendMessage Hnd, WM_CLOSE, 0&, 0&
End Sub
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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