
-----------------------------------
HazySmoke)345
Sat Dec 31, 2005 9:59 pm

Task Manager in VB?
-----------------------------------
Since a virus busted the task manager in my Windows 2000. I now have no defence against the annoying spywares that's ticking in my computer. So, one day, this weird idea came to me and I want to make a task manager myself. The API function TerminateProcess should do the job on ending the processes, but how do you find all the processes that's running? And, also, the syntax for Terminate Process looks like this:
Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Where am I supposed to get the "hProcess" value?

-----------------------------------
Brightguy
Wed Jan 04, 2006 10:33 pm

Re: Task Manager in VB?
-----------------------------------
You can use the EnumProcesses function to get a list of all the process identifiers, and you can easily find Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF

Private Sub Command1_Click()
    Dim hwnd As Long, pId As Long, pHandle As Long
    
    hwnd = FindWindow(vbNullString, "Calculator")
    GetWindowThreadProcessId CLng(hwnd), pId
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
    TerminateProcess pHandle, 0
    CloseHandle pHandle
End Sub


-----------------------------------
HazySmoke)345
Thu Jan 05, 2006 12:46 pm


-----------------------------------
Thanks so much. +11 bits.   :D
