Basicamente, vc precisa de 2 coisas: achar os processos (ou seja, os Handles deles) e depois mandar fechar o desejado.
Para mandar fechar uma aplicação, é relativamente simples: Ponha o código abaixo em um módulo, e é só chamar a função passado o Hwnd (Handle) da aplicação que você quer derrubar:
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function KillApp(lngHwnd as Long) as Boolean
On Local Error Resume Next
Dim lngResult As Long
Const WM_CLOSE = &H10
lngResult = PostMessage(lngHwnd, WM_CLOSE, 0&, 0&)
KillApp = Iif(lngResult = 1, True, False)
On Local Error Goto 0
End Sub
Para chamá-la:
If KillApp(lngHwnd) Then
Msgbox "Aplicativo fechado"
Else
Msgbox "Falha ao fechar aplicativo"
End If
Para achar o Handle, basta usar as API FindWindow. Há também como puxar tudo que está aberto (inclusive as janelas ocultas, usando as API's GetWindow, GetWindowText e GetClassName (esta última só prá levantar de que classe é a janela, não importa muito ao processo). O exemplo abaixo ilustra isso. Para ver ele funcionando, crie um Form e insira nele um ListView. Nomeie este ListView para lvwBig.
Primeiramente, no módulo descrito acima, insira o seguinte:
' GetWindow() Constants
Public Const GW_HWNDNEXT = 2
'API Declaration
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Então insira a função abaixo no Form e chame-a pelo Form_Load, num Timer, ou onde você preferir.
Private Sub GetApps()
Dim strResult As String * 128
Dim lngHwnd As Long
Dim lngHwnd1 As Long
Dim lstItem As ListItem
Dim strClassName As String 'Variable to return the Class Name of Window
Dim strWindowText As String 'Variable to return the Window Text
With lvwBig
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Window Title", 4000, lvwColumnLeft
.ColumnHeaders.Add , , "Handle", 1000, lvwColumnCenter
.ColumnHeaders.Add , , "Class", 3000, lvwColumnLeft
End With
'Set lngHwnd Min value to the handle's window of the application ...
lngHwnd = Me.hwnd
Do Until lngHwnd = 0
'Get window text of the actual window ...
GetWindowText lngHwnd, strResult, Len(strResult)
strWindowText = Trim(Mid(strResult, 1, InStr(1, strResult, vbNullChar, vbTextCompare) - 1))
If InStr(1, strWindowText, Me.Caption, vbTextCompare) = 0 And Trim(strWindowText) <> "" Then
'Get class name of the actual window ...
GetClassName lngHwnd, strResult, Len(strResult)
strClassName = Mid(strResult, 1, InStr(1, strResult, vbNullChar, vbTextCompare) - 1)
Set lstItem = lvwBig.ListItems.Add(, , strWindowText, , 1)
lstItem.SubItems(1) = Trim(Str(lngHwnd))
lstItem.SubItems(2) = strClassName
End If
lngHwnd1 = GetWindow(lngHwnd, GW_HWNDNEXT)
lngHwnd = lngHwnd1
Loop
End Sub