Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => 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 (VB) [Seleccionar]
Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean
  Dim lhwndProcess As Long
  Dim lExitCode As Long
  Dim lRetVal As Long
  Dim lhThisProc As Long
  Dim lhTokenHandle As Long
  Dim tLuid As LUID
  Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES
  Dim lBufferNeeded As Long

  Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1
  Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20
  Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege"
  Const SE_PRIVILEGE_ENABLED = &H2

  On Error Resume Next
  If lHwndWindow Then
      'Get the process ID from the window handle
      lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID)
  End If

  If lProcessID Then
      'Give Kill permissions to this process
      lhThisProc = GetCurrentProcess

      OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle
      LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid
      'Set the number of privileges to be change
      tTokenPriv.PrivilegeCount = 1
      tTokenPriv.TheLuid = tLuid
      tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED
      'Enable the kill privilege in the access token of this process
      AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), _
      tTokenPrivNew, lBufferNeeded

      'Open the process to kill
      lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID)

      If lhwndProcess Then
          'Obtained process handle, kill the process
          ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode))
          Call CloseHandle(lhwndProcess)
      End If
  End If
  On Error GoTo 0
End Function 



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.