Solved

Closing Program

Posted on 2003-11-26
4
577 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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