Solved

Closing Program

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

690 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