Attribute VB_Name = "End_Process" Const MAX_PATH = 260 Const TH32CS_SNAPPROCESS = 2& Private Type PROCESSENTRY32 lSize As Long lUsage As Long lProcessId As Long lDefaultHeapId As Long lModuleId As Long lThreads As Long lParentProcessId As Long lPriClassBase As Long lFlags As Long sExeFile As String * MAX_PATH End Type Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) Private Declare Function CreateToolhelpSnapshot Lib "kernel32" _ Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _ ByVal lProcessId As Long) As Long Private Declare Function ProcessFirst Lib "kernel32" _ Alias "Process32First" (ByVal hSnapshot As Long, _ uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "kernel32" _ Alias "Process32Next" (ByVal hSnapshot As Long, _ uProcess As PROCESSENTRY32) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _ ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, _ ByVal uExitCode As Long) As Long Public Sub EndProcess(procName As String) Dim sExeName As String Dim sPid As String Dim sParentPid As String Dim lSnapShot As Long Dim r As Long Dim uProcess As PROCESSENTRY32 Dim fProc As Long lSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) uProcess.lSize = Len(uProcess) r = ProcessFirst(lSnapShot, uProcess) Do While r sExeName = Left(uProcess.sExeFile, InStr(1, uProcess.sExeFile, vbNullChar) - 1) If LCase(sExeName) = LCase(procName) Then fProc = uProcess.lProcessId Exit Do End If r = ProcessNext(lSnapShot, uProcess) Loop CloseHandle (lSnapShot) Dim mProcID As Long mProcID = OpenProcess(1&, -1&, fProc) TerminateProcess mProcID, 0& End Sub