[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Closing Program

Posted on 2003-11-26
4
Medium Priority
?
603 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 150 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

656 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