Private Const PROCESS_TERMINATE As Long = (&H1)
Private Const WM_QUIT As Long = &H12
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function PostThreadMessage Lib "user32.dll" Alias "PostThreadMessageA" (ByVal idThread As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Sub Dong(ByVal processID As Long)
Dim hProc As Long
hProc = OpenProcess(PROCESS_TERMINATE, 0, processID)
If hProc <> 0 Then
TerminateProcess hProc, 0
CloseHandle hProc
End If
End Sub
Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim threadID As Long, processID As Long
threadID = GetWindowThreadProcessId(hwnd, processID)
If processID = lParam Then
PostThreadMessage threadID, WM_QUIT, 0, 0
EnumWindowsProc = False
Else
EnumWindowsProc = True
End If
End Function
Sub CloseByTerminate()
Dim res
res = Shell("outlook")
Sleep 10000
Dong res
End Sub
Sub CloseByMessage()
Dim res, hwnd As Long
res = Shell("outlook")
Sleep 10000
EnumWindows AddressOf EnumWindowsProc, res
End Sub