ho un esempio in vb che chima le api
ho solo questo, chon non usa un TerminateProcess, ma invia un msg di chuisura alla finenstecodice:Private Const TH32CS_SNAPPROCESS As Long = 2& Private Const MAX_PATH As Long = 260 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type Private Declare Sub CloseHandle Lib "Kernel32.dll" (ByVal hPass As Long) Private Declare Function CreateToolhelpSnapshot Lib "Kernel32.dll" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function ProcessFirst Lib "Kernel32.dll" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "Kernel32.dll" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private 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 Private Declare Function IsWindow Lib "User32" (ByVal Hwnd As Long) As Long Private Declare Function GetWindow Lib "User32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowLong Lib "User" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long Const GW_OWNER = 4 Const GWL_STYLE = -16 Const WS_DISABLED = &H8000000 Const WS_CANCELMODE = &H1F Const WM_CLOSE = &H10 Private Function ProcessoAttivo(NomeProcesso As String) As Boolean Dim uProcess As PROCESSENTRY32 Dim continua As Long Dim Verifica As String Dim hSnapShot hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) If hSnapShot = 0 Then Exit Function uProcess.dwSize = Len(uProcess) continua = ProcessFirst(hSnapShot, uProcess) ProcessoAttivo = False Do While continua continua = ProcessNext(hSnapShot, uProcess) Verifica = uProcess.szExeFile If Trim(Verifica) <> "" Then If InStr(1, LCase(Left(Verifica, InStr(1, Verifica, Chr(0)) - 1)), LCase(NomeProcesso)) <> 0 Then ProcessoAttivo = True: Exit Function End If Loop Call CloseHandle(hSnapShot) End Function Public Sub tiraGiu(par) Dim winHwnd As Long winHwnd = FindWindow(vbNullString, CStr(par)) If winHwnd <> 0 Then PostMessage winHwnd, WS_CANCELMODE, 0, 0& PostMessage winHwnd, WM_CLOSE, 0, 0& End If end sub If ProcessoAttivo("Nome Processo") = True Then tiraGiu "Nome Processo" End If
Per avere il processId forse lo trovi dentro alla struttura PROCESSENTRY32, quindi la varibile uProcess di ProcessoAttivo.
Con questo puoi usare il termitateProcess
Però non so come fai a distinguere ad esempio tra le diverse istanze di IE

Rispondi quotando