Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

Finalizar un programa en ejecución

  • 0 Respuestas
  • 1973 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado ANTRAX

  • *
  • Administrator
  • Mensajes: 5499
  • Actividad:
    16.67%
  • Reputación 36
  • ANTRAX
    • Ver Perfil
    • Underc0de
    • Email
  • Skype: underc0de.org
  • Twitter: @Underc0de
« en: Julio 26, 2010, 01:43:06 pm »
Modulo de Clase:
---------------------------------------------------------
Código: Visual Basic
  1. Option Explicit
  2. Private Const MAX_PATH& = 260
  3. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  4. Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
  5. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  6. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
  7. Private Declare Function GetWindowThreadProcessId& Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
  8. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
  9. Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
  10. Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
  11. Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal ProcessID As Long, ByVal ServiceFlags As Long) As Long
  12. Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
  13.  
  14. Private Type PROCESSENTRY32
  15. dwSize As Long
  16. cntUsage As Long
  17. th32ProcessID As Long
  18. th32DefaultHeapID As Long
  19. th32ModuleID As Long
  20. cntThreads As Long
  21. th32ParentProcessID As Long
  22. pcPriClassBase As Long
  23. dwFlags As Long
  24. szexeFile As String * MAX_PATH
  25. End Type
  26. Public Sub KillProcess(ByVal ProcessID As Long)
  27. Dim hp&
  28. hp& = OpenProcess(1&, -1&, ProcessID)
  29. TerminateProcess hp&, 0&
  30. DoEvents
  31. End Sub
  32.  
  33. Public Function FindWindowByClass(ByVal WindowClassName As String) As Long
  34. FindWindowByClass = FindWindow(WindowClassName, vbNullString)
  35. End Function
  36.  
  37. Public Function FindProcessByWindowClass(ByVal WindowClassName As String) As Long
  38. Dim pid&
  39. GetWindowThreadProcessId FindWindowByClass(WindowClassName), pid&
  40. FindProcessByWindowClass = pid&
  41. End Function
  42.  
  43. Public Function FindProcessByName(ByVal AppPath As String) As Long
  44. Dim AppPaths, ProcessIds, ParentProcessIds, i As Integer
  45. ListRunningApps AppPaths, ProcessIds, ParentProcessIds
  46. i = FindInArray(AppPaths, AppPath)
  47. If i = -1 Then
  48. FindProcessByName = 0
  49. Else
  50. FindProcessByName = ProcessIds(i)
  51. End If
  52. End Function
  53.  
  54. Public Sub ListRunningApps(ByRef AppPaths, ByRef ProcessIds, ByRef ParentProcessIds)
  55. Dim uProcess As PROCESSENTRY32
  56. Dim rProcessFound As Long
  57. Dim hSnapshot As Long
  58. Dim szExename As String
  59. Dim i As Integer
  60. Const TH32CS_SNAPPROCESS As Long = 2&
  61.  
  62. AppPaths = Array()
  63. ProcessIds = Array()
  64. ParentProcessIds = Array()
  65.  
  66. uProcess.dwSize = Len(uProcess)
  67. hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
  68. rProcessFound = ProcessFirst(hSnapshot, uProcess)
  69.  
  70. Do While rProcessFound
  71. i = InStr(1, uProcess.szexeFile, Chr(0))
  72. szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
  73. AppendToArray AppPaths, szExename
  74. AppendToArray ProcessIds, uProcess.th32ProcessID
  75. AppendToArray ParentProcessIds, uProcess.th32ParentProcessID
  76. rProcessFound = ProcessNext(hSnapshot, uProcess)
  77. Loop
  78. End Sub
  79. Public Function FindInArray(List As Variant, Item As Variant) As Integer
  80. Dim i As Integer
  81. For i = 0 To UBound(List)
  82. If UCase("" & List(i)) = UCase("" & Item) Then
  83. FindInArray = i
  84. Exit Function
  85. End If
  86. Next
  87. FindInArray = -1
  88. End Function
  89. Private Sub AppendToArray(List As Variant, Item As Variant)
  90. ReDim Preserve List(UBound(List) + 1)
  91. List(UBound(List)) = Item
  92. End Sub

-------------------
y el formulario :
-----------------------
Option Explicit
Código: Visual Basic
  1. Private NombreProceso, IdentificacionProceso, ParentIdentificacionProceso
  2. Private PM As Class1, i As Integer
  3.  
  4. Private Sub Command1_Click()
  5. Set PM = New Class1
  6. PM.ListRunningApps NombreProceso, IdentificacionProceso, ParentIdentificacionProceso
  7. For i = 0 To UBound(NombreProceso)
  8. If NombreProceso(i) = "winamp.exe" Then
  9. PM.KillProcess IdentificacionProceso(i)
  10. DoEvents
  11. End If
  12. Next
  13. End Sub


*El nombre del proceso es el que muestra el programa en lo sprocesos de Windows.
« Última modificación: Mayo 12, 2014, 03:18:20 pm por Expermicid »


 

¿Te gustó el post? COMPARTILO!



Actualizador para tus programa [modulo]

Iniciado por alexander1712

Respuestas: 3
Vistas: 5077
Último mensaje Julio 14, 2016, 10:16:11 pm
por noxonsoftwares
Ejecutar un programa y esperar que finalice

Iniciado por ANTRAX

Respuestas: 0
Vistas: 1979
Último mensaje Julio 26, 2010, 01:55:55 pm
por ANTRAX
Ejecutar un solo ejemplar de un programa

Iniciado por ANTRAX

Respuestas: 0
Vistas: 2109
Último mensaje Julio 26, 2010, 10:19:50 am
por ANTRAX
Ejecutar cualquier programa

Iniciado por ANTRAX

Respuestas: 0
Vistas: 1956
Último mensaje Julio 26, 2010, 11:49:25 am
por ANTRAX
Programa que registra sus ocx y dll

Iniciado por ANTRAX

Respuestas: 0
Vistas: 2285
Último mensaje Julio 26, 2010, 03:44:16 pm
por ANTRAX