You can use the code posted in thread222-834688 to obtain the process identifier of any running process by its name.
After obtaining the process Id, you can use the OpenProcess function to obtain a handle to that process and terminate it using TerminateProcess function.
Here the complete code is being posted again because the code in the above-mentioned thread has a very small bug.
___
[tt]
Option Explicit
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 bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Const PROCESS_TERMINATE = (&H1)
Const TH32CS_SNAPPROCESS = 2
Const MAX_PATH = 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
Function GetProcessId(Process As String) As Long
Dim hSnapShot As Long, pe32 As PROCESSENTRY32
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, ByVal 0)
pe32.dwSize = Len(pe32)
ProcessFirst hSnapShot, pe32
Do
If InStr(1, pe32.szExeFile, Process & vbNullChar, vbTextCompare) = 1 Then
GetProcessId = pe32.th32ProcessID
Exit Do
End If
Loop While ProcessNext(hSnapShot, pe32)
CloseHandle hSnapShot
End Function
Private Sub Form_Load()
Dim ProcessId As Long, hProcess As Long
'Obtain the process id
ProcessId = GetProcessId("wordpad.exe")
'Obtain process handle
hProcess = OpenProcess(PROCESS_TERMINATE, 0, ProcessId)
'Terminate the process
TerminateProcess hProcess, 0
'Close the process handle
CloseHandle hProcess
Unload Me
End Sub[/tt]