''-----------------------------------------For Delete From TaskManager
Private Const MAX_PATH As Long = 260
Private Const TH32CS_SNAPPROCESS = &H2&
Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
Private Const PROCESS_TERMINATE As Long = (&H1)
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 Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As PROCESSENTRY32) 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.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 Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long
Sub KillProcess(ByVal sExeName As String)
Dim lSnapshot As Long, lNextProcess As Long
Dim tPE As PROCESSENTRY32
' Create Snapshot
lSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If lSnapshot <> -1 Then
tPE.dwSize = LenB(tPE)
' Find first process
lNextProcess = Process32First(lSnapshot, tPE)
Do While lNextProcess
' Find specified process
If UCase(sExeName) = UCase(Left(tPE.szExeFile, Len(sExeName))) And Len(sExeName) > 0 Then
Dim lProcess As Long
Dim lExitCode As Long
' Open Process
lProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_TERMINATE, False, tPE.th32ProcessID)
' Get Exitcode
GetExitCodeProcess lProcess, lExitCode
' Terminate Process
TerminateProcess lProcess, lExitCode
' Close Handle
CloseHandle (lProcess)
Exit Do
End If
lNextProcess = Process32Next(lSnapshot, tPE)
Loop
' Close Handle
CloseHandle (lProcess)
End If
End Sub
Sub TaskManager(ProgramName As String)
Dim nStr As String
Dim hSnapshot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapshot = 0 Then Exit Sub
uProcess.dwSize = Len(uProcess)
r = ProcessFirst(hSnapshot, uProcess)
Do While r
nStr = uProcess.szExeFile
If UCase(Left(UCase(nStr), Len(ProgramName))) = UCase(ProgramName) Then
KillProcess (ProgramName)
End If
r = ProcessNext(hSnapshot, uProcess)
Loop ' Do all the processs
End Sub
Function FindManager(ProgramName As String) As Boolean
Dim nStr As String
Dim hSnapshot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
FindManager = False
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapshot = 0 Then Exit Function
uProcess.dwSize = Len(uProcess)
r = ProcessFirst(hSnapshot, uProcess)
Do While r
nStr = uProcess.szExeFile
If UCase(Left(UCase(nStr), Len(ProgramName))) = UCase(ProgramName) Then
FindManager = True
End If
r = ProcessNext(hSnapshot, uProcess)
Loop ' Do all the processs
End Function