Tools Links Login

Close Any Application

This code will Close any application based on its windows caption

Original Author: Alex

API Declarations

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10

Code


Public Function CloseApplication(byVal sAppCaption As String) As Boolean
  Dim lHwnd As Long
  Dim lRetVal As Long
  
  lHwnd = FindWindow(vbNullString, sAppCaption)
  If lHwnd <> 0 Then
    lRetVal = PostMessage(lHwnd, WM_CLOSE, 0&, 0&)
  End If
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 98 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.