Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: sp26 en 18 Mayo 2007, 21:08 pm



Título: Verificar procesos - Duda
Publicado por: sp26 en 18 Mayo 2007, 21:08 pm
Una pequeña duda, como hago para verificar que "cierto proceso" esta en ejecucion y si no esta en ejecucion "Ejecutar cierto proceso".



Título: Re: Verificar procesos - Duda
Publicado por: Hendrix en 18 Mayo 2007, 21:19 pm
Este codigo lo hice yo hace unos dias:

En un Modulo:

Código:
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260

Private Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * MAX_PATH
End Type

Private Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)

Public Function depurar(cadena As String) As String
Dim a As String
Dim b As String

For i = 1 To Len(cadena)
a = Mid(cadena, i, 1)
If Asc(a) = 0 Then
depurar = Mid(cadena, 1, i - 1)
Exit Function
End If
Next
End Function


Public Function IsMessenger() As Boolean
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
Dim var As Variant
Dim lista As String
Dim proc As String
Dim subs As String


hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
R = Process32First(hSnapShot, uProcess)
   
Do While R
    R = Process32Next(hSnapShot, uProcess)
    lista = lista & uProcess.szExeFile & "|"
Loop

Call CloseHandle(hSnapShot)

lista = Left(lista, Len(lista) - 1)

var = Split(lista, "|")

IsMessenger = False

For i = 0 To UBound(var)
subs = var(i)
proc = depurar(subs)
If proc = "msmsgs.exe" Then
IsMessenger = True
Exit For
Exit Function
End If
Next
End Function

En El Form:

Código:
Private Sub Form_Load()
If IsMessenger = True Then
MsgBox "El Messenger esta abierto"
Else
MsgBox "El Messenger esta cerrado"
End If
End Sub

Este codigo detecta si el proceso del MSN esta abierto...

Un Saludo.



Título: Re: Verificar procesos - Duda
Publicado por: sp26 en 19 Mayo 2007, 05:02 am
Funciona... Gracias :).


Título: Re: Verificar procesos - Duda
Publicado por: c4st0r en 30 Julio 2007, 00:30 am
Y no seria mas facil y con menos codigo hacer desde vb tasklist > nombre.txt
y ver si en ese nombre.txt aparece el nombre del proceso??? aunque mas chapucero


Título: Re: Verificar procesos - Duda
Publicado por: Hendrix en 30 Julio 2007, 10:36 am
aunque mas chapucero

Tu lo has dicho....y si el PC donde uieres hacer eso no tiene el tasklist (ya sea un XP home por ejemplo).... :rolleyes: