Guest User

Untitled

a guest
Jul 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. '-------------------------------------------------------
  2. Type PROCESSENTRY32
  3. dwSize As Long
  4. cntUsage As Long
  5. th32ProcessID As Long
  6. th32DefaultHeapID As Long
  7. th32ModuleID As Long
  8. cntThreads As Long
  9. th32ParentProcessID As Long
  10. pcPriClassBase As Long
  11. dwFlags As Long
  12. szexeFile As String * 260
  13. End Type
  14. '-------------------------------------------------------
  15. Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, _
  16. ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
  17.  
  18. Declare Function ProcessFirst Lib "kernel32.dll" Alias "Process32First" (ByVal hSnapshot As Long, _
  19. uProcess As PROCESSENTRY32) As Long
  20.  
  21. Declare Function ProcessNext Lib "kernel32.dll" Alias "Process32Next" (ByVal hSnapshot As Long, _
  22. uProcess As PROCESSENTRY32) As Long
  23.  
  24. Declare Function CreateToolhelpSnapshot Lib "kernel32.dll" Alias "CreateToolhelp32Snapshot" ( _
  25. ByVal lFlags As Long, lProcessID As Long) As Long
  26.  
  27. Declare Function TerminateProcess Lib "kernel32.dll" (ByVal ApphProcess As Long, _
  28. ByVal uExitCode As Long) As Long
  29.  
  30. Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
  31.  
  32. Module
  33.  
  34. '-------------------------------------------------------
  35. Public Sub KillProcess(NameProcess As String)
  36. Const PROCESS_ALL_ACCESS = &H1F0FFF
  37. Const TH32CS_SNAPPROCESS As Long = 2&
  38. Dim uProcess As PROCESSENTRY32
  39. Dim RProcessFound As Long
  40. Dim hSnapshot As Long
  41. Dim SzExename As String
  42. Dim ExitCode As Long
  43. Dim MyProcess As Long
  44. Dim AppKill As Boolean
  45. Dim AppCount As Integer
  46. Dim i As Integer
  47. Dim WinDirEnv As String
  48.  
  49. If NameProcess <> "" Then
  50. AppCount = 0
  51.  
  52. uProcess.dwSize = Len(uProcess)
  53. hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
  54. RProcessFound = ProcessFirst(hSnapshot, uProcess)
  55.  
  56. Do
  57. i = InStr(1, uProcess.szexeFile, Chr(0))
  58. SzExename = LCase$(Left$(uProcess.szexeFile, i - 1))
  59. WinDirEnv = Environ("Windir") + "\"
  60. WinDirEnv = LCase$(WinDirEnv)
  61.  
  62. If Right$(SzExename, Len(NameProcess)) = LCase$(NameProcess) Then
  63. AppCount = AppCount + 1
  64. MyProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
  65. AppKill = TerminateProcess(MyProcess, ExitCode)
  66. Call CloseHandle(MyProcess)
  67. End If
  68. RProcessFound = ProcessNext(hSnapshot, uProcess)
  69. Loop While RProcessFound
  70. Call CloseHandle(hSnapshot)
  71. End If
  72.  
  73. End Sub
  74. '-------------------------------------------------------
Add Comment
Please, Sign In to add comment