Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: $Edu$ en 10 Septiembre 2011, 18:10 pm



Título: Verificar y matar proceso
Publicado por: $Edu$ en 10 Septiembre 2011, 18:10 pm
Como hago para verificar si existe un proceso y luego matarlo? no encuentro algo bueno para hacerlo bien, me pueden ayudar?


Título: Re: Verificar y matar proceso
Publicado por: x64core en 10 Septiembre 2011, 18:23 pm
cmd:

shell "taskkill /f /im nombredeproceso.exe"


alter 1:

Código
  1. Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean
  2.  Dim lhwndProcess As Long
  3.  Dim lExitCode As Long
  4.  Dim lRetVal As Long
  5.  Dim lhThisProc As Long
  6.  Dim lhTokenHandle As Long
  7.  Dim tLuid As LUID
  8.  Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES
  9.  Dim lBufferNeeded As Long
  10.  
  11.  Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1
  12.  Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20
  13.  Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege"
  14.  Const SE_PRIVILEGE_ENABLED = &H2
  15.  
  16.  On Error Resume Next
  17.  If lHwndWindow Then
  18.      'Get the process ID from the window handle
  19.      lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID)
  20.  End If
  21.  
  22.  If lProcessID Then
  23.      'Give Kill permissions to this process
  24.      lhThisProc = GetCurrentProcess
  25.  
  26.      OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle
  27.      LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid
  28.      'Set the number of privileges to be change
  29.      tTokenPriv.PrivilegeCount = 1
  30.      tTokenPriv.TheLuid = tLuid
  31.      tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED
  32.      'Enable the kill privilege in the access token of this process
  33.      AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), _
  34.      tTokenPrivNew, lBufferNeeded
  35.  
  36.      'Open the process to kill
  37.      lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID)
  38.  
  39.      If lhwndProcess Then
  40.          'Obtained process handle, kill the process
  41.          ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode))
  42.          Call CloseHandle(lhwndProcess)
  43.      End If
  44.  End If
  45.  On Error GoTo 0
  46. End Function  
  47.  


habia un codigo de karcrack o de cobein no recuerdo que era muy bueno :P crei que lo tenia guardado pero no lo encuentro :P


Título: Re: Verificar y matar proceso
Publicado por: $Edu$ en 10 Septiembre 2011, 18:41 pm
Ese codigo creo que me serviria si tiene ventana mi proceso, pero no tiene :/ buscare como usar el taskill sin que largue error si no se encuentra el proceso, gracias


Título: Re: Verificar y matar proceso
Publicado por: calk9 en 14 Septiembre 2011, 00:43 am
Puedes usar KILL_PROC_BY_NAME.