Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 27,947 times

Related Categories

Close Application by Caption - The code

mrjdesign

The code

Place the following code in a module

Option Explicit

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

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

Public Const WM_CLOSE = &H10

'THIS WILL CLOSE AN APP BY CAPTION ONLY

Public Sub CloseProgram(ByVal Caption As String)
On Error GoTo EVT
Dim lngWin As Long
lngWin = FindWindow(vbNullString, Caption)
If lngWin = 0 Then Exit Sub
SendMessage lngWin, WM_CLOSE, 0&, 0&

Exit Sub
EVT:
Err.Clear
Resume Next
End Sub

call the code above by Call CloseProgram("My Applications Caption")

Please note that the code above will terminate without notcie if an error occures.
This is to make it as stealth as possible. Avoiding bugs and stuff.

If anyone has a good example on how to do this without knowing any part of the caption, basically doing it by closing a runing EXE file, I would very much appreciate an email about that.


©2001 - All Rights Reserved - MRJ Design
The source code samples and information pertained within this document are considered copyrighted material and may not be re-distributed by electronic or other media in any form or fashion whatsoever, withou

Comments