Show & Kill Processes
Show & Kill Processes:trang này đã được đọc lần Hướng dẫn viết chương trình hiển thị tất cả tiến trình đang chạyMột số chương trình của Windows hay trojan chạy ẩn mà chúng ta không hay biết, TaskManager chỉ hiển thị một phần nào đó. Chương trình sau sẽ hiện tất cả các tiến trình đang chạy, và có thể tắt tiến trình đó nếu như ta không muốn chạy (Ví dụ Trojan chẳng hạn). Thành phần của chương trình- Hàm API:Private Declare Function GetWindow Lib "user32" _(ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Declare Function GetParent Lib "user32" _(ByVal hwnd As Long) As LongPrivate Declare Function GetWindowTextLength Lib _"user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As LongPrivate Declare Function GetWindowText Lib "user32" _Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _lpString As String, ByVal cch As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongConst GW_HWNDFIRST = 0Const GW_HWNDNEXT = 2- Đối tượng3 Command Button có thuộc tính (Name) lần lượt là cmdKillProcess, cmdRefresh, cmdQuit1 ListBox có thuộc tính (Name) là lstTientrinhMã nguồnPrivate Declare Function GetWindow Lib "user32" _(ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Declare Function GetParent Lib "user32" _(ByVal hwnd As Long) As LongPrivate Declare Function GetWindowTextLength Lib _"user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As LongPrivate Declare Function GetWindowText Lib "user32" _Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _lpString As String, ByVal cch As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongConst GW_HWNDFIRST = 0Const GW_HWNDNEXT = 2Dim TenTienTrinh As StringPrivate Sub cmdKillProcess_Click()Dim Ret As LongDim hwnd As Long On Error GoTo Refreshhwnd = FindWindow(vbNullString, TenTienTrinh)If hwnd <> 0 ThenRet = PostMessage(hwnd, &H10, 0, 0)If Ret = 0 ThenMsgBox "Khong the tat chuong trinh " & TenTienTrinh, vbExclamation, "Warning"ElseMsgBox "Da tat chuong trinh " & TenTienTrinh, vbInformation, "Warning"End IfEnd IfRefresh:HienThiTienTrinhEnd SubPrivate Sub cmdQuit_Click()Unload MeEnd SubPrivate Sub Form_Load()HienThiTienTrinhEnd SubSub HienThiTienTrinh()Dim HwndHienTai As LongDim Length As Long, i As LongDim Parent As LongDim TienTrinh As Stringi = 0lstTientrinh.ListItems.ClearlstTientrinh.ColumnHeaders.Add , , "STT"lstTientrinh.ColumnHeaders.Add , , "Processes"lstTientrinh.ColumnHeaders.Item(1).Width = 500lstTientrinh.ColumnHeaders.Item(2).Width = lstTientrinh.Width - 400HwndHienTai = GetWindow(frmShowProcess.hwnd, GW_HWNDFIRST)While HwndHienTai <> 0Length = GetWindowTextLength(HwndHienTai)TienTrinh = Space(Length + 1)Length = GetWindowText(HwndHienTai, TienTrinh, Length + 1)TienTrinh = Left(TienTrinh, Len(TienTrinh) - 1)If Length <> 0 ThenIf Me.Caption <> TienTrinh ThenIf TienTrinh <> "taskmon" Theni = i + 1lstTientrinh.ListItems.Add(, , i).ListSubItems.Add , , TienTrinhEnd IfEnd IfEnd IfHwndHienTai = GetWindow(HwndHienTai, GW_HWNDNEXT)DoEventsWendEnd Sub Private Sub lstTientrinh_ItemClick(ByVal Item As MSComctlLib.ListItem)TenTienTrinh = Item.ListSubItems(1).TextEnd Sub . Left(TienTrinh, Len(TienTrinh) - 1)If Length <> 0 ThenIf Me.Caption <> TienTrinh ThenIf TienTrinh <> "taskmon" Theni = i + 1lstTientrinh.ListItems.Add(,. PostMessage(hwnd, &H10, 0, 0)If Ret = 0 ThenMsgBox "Khong the tat chuong trinh " & TenTienTrinh, vbExclamation, "Warning"ElseMsgBox "Da