Lukke et Oracel program (Forms)
Jeg har et program som jeg gerne vil kunne lukke via en VB-app.Programmet bliver åbnet via en bat-fil på klienten hvor der så fra serveren bliver hentet og startet en instans af programmet i Oracel-Forms.
jeg kan se(og lukke) programmet i Task Manageren, der hedder det xxxxx.EXE. Caption på formen hedder yyyyy.827.zzz
Jeg har hentet understående kode andet sted her på eksperten. Det virker fint på andre åbne programmer, men bare ikke på det sk.... Oracle program.
Er der nogle der kan hjælpe.
Jeg er parat til at "betale"ekstra point for det rigtige svar.
'----------------------------------------- Module1 -----------------------------------------
Option Explicit
Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long)
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long)
Dim sPattern As String, hFind As Long
Private Function FindActivateTitle(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim k As Long, sName As String
If IsWindowVisible(hwnd) And GetParent(hwnd) = 0 Then
sName = Space$(128)
k = GetWindowText(hwnd, sName, 128)
If k > 0 Then
sName = Left$(sName, k)
If lParam = 0 Then sName = UCase(sName)
If sName Like sPattern Then
hFind = hwnd
FindActivateTitle = 0
Exit Function
End If
End If
End If
FindActivateTitle = 1
End Function
Function ActivateAppHwnd(sTitle As String, Optional sMatchCase As Boolean = True) As Long
sPattern = sTitle: hFind = 0
If Not sMatchCase Then sPattern = UCase(sPattern)
EnumWindows AddressOf FindActivateTitle, sMatchCase
ActivateAppHwnd = hFind
End Function
'----------------------------------------- Module1 -----------------------------------------
'----------------------------------------- Form1 -----------------------------------------
Option Explicit
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private Sub Timer1_Timer()
'lukker Microsoft Internet Explore
PostMessage ActivateAppHwnd("*Microsoft Internet Explore*", False), WM_CLOSE, 0&, 0&
End Sub
'----------------------------------------- Form1 -----------------------------------------
