Fremdanwendung per VB schliessen
11.11.2004 11:15:50
Nike
wie ist es moeglich eine andere Anwendung per VB zu schliessen?
Extra nicht VBA, sondern VB...
Irgendwie mit der shell?
Das unten angehaengte hab ich bisher gefunden,
aber leider hab ich wohl die falsche Caption,
kennt jemand ne Moeglichkeit, wie ich die Caption aller
zu Zeit geoeffneten Fenster auflisten lassen kann?
Kurze info waere nett...
Bye
Nikolai
' Closing another Application
' *************************************************************
' *********************************************************
'compat:vb3,vb4-16
'Close_External_Application
' Description:To have a program programmatically close anoth
' er program, use this code
' By: VB Pro'
' Inputs:strCaptionTitle--caption title of window to close
' Returns:true on success, else false
' Assumes:None
' Side Effects:None'
' Close an existing program
' *********************************************************
Declare
Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
Declare
Function GetWindowTask Lib "User" (ByVal hWnd As Integer) As Integer
Declare
Function PostAppMessage Lib "User" (ByVal hTask As Integer, ByVal wMsg _
As Integer, ByVal wParam As Integer, lParam As Any) As Integer
Public Const WM_QUIT = &H12
' ***************** The command button would look like this:
Sub Test()
Close_External_Application "SAP Logon 620"
End Sub
Function Close_External_Application(ByVal strCaptionTitle As String) _
As Boolean
Dim intWindowHandle As Integer
Dim intTaskHandle As Integer
Dim intPostReturnValue As Integer
' *************** set defaults
Close_External_Application = False
' *************** get handle of window matching caption
intWindowHandle = FindWindow(0&, strCaptionTitle)
If (intWindowHandle <> 0) Then
' *************** window found
intTaskHandle = GetWindowTask(intWindowHandle)
intPostReturnValue = PostAppMessage(intTaskHandle, WM_QUIT, 0, 0&)
' *************** set return value
Close_External_Application = True
End If
End Function