Solved

Closing Program

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now