elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  ejecutar un exe, si esta el otro
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ejecutar un exe, si esta el otro  (Leído 3,873 veces)
CAR3S?


Desconectado Desconectado

Mensajes: 343


Level xXx


Ver Perfil
ejecutar un exe, si esta el otro
« en: 27 Enero 2011, 01:11 am »

una pregunta, necesito ejecutar un .exe solo cuando se abre el proceso "bolas.exe".

me explico?

seria, chequear si existe el proceso bolas.exe , y asi, un bucle me parece que seria... si existe el bolas.exe , se abre otro .exe , y cuando lo cierran, se ciera el otro .exe.

alguna api o algo?


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: ejecutar un exe, si esta el otro
« Respuesta #1 en: 27 Enero 2011, 02:45 am »

.
Quisas haciendo un hook al mensaje WH_CBT.

P.D.: No esperes codigo, la MSDN es suficiente.

Dulces Lunas!¡.


En línea

The Dark Shadow is my passion.
agus0


Desconectado Desconectado

Mensajes: 360



Ver Perfil
Re: ejecutar un exe, si esta el otro
« Respuesta #2 en: 27 Enero 2011, 03:48 am »

Eso No Creo que lo puedas hacer es decir vas a necesitar un Programa que este avierto constantemente revisando que el Progreso "bolsa.exe" No este en ejecucion y si este Programa detecta que aparece "bolsa.exe" Ejecute a otro exe o bien una instruccion Tengo un Modulito que Chequie si un .exe Esta en ejecucion pero Como Dijo Black Seria interesante que lo hagas por Tu cuenta.. si se te complica comenta con nosotros para eso estamos y la idea es aprender... ;-) ;-)
En línea

abdiel2475

Desconectado Desconectado

Mensajes: 32


Ver Perfil
Re: ejecutar un exe, si esta el otro
« Respuesta #3 en: 27 Enero 2011, 05:32 am »

Puedes usar el FindWindow
pero para eso tendrias que tener un programa usando FindWindow y que este checando eso y luego ya...
En línea

agus0


Desconectado Desconectado

Mensajes: 360



Ver Perfil
Re: ejecutar un exe, si esta el otro
« Respuesta #4 en: 27 Enero 2011, 05:39 am »

FindWindows No Le Conviene Por Varias Razones A mi Humilde Forma de Ver...

Primero en Principal puede que la app que quiere saber si esta en ejecucion no tiene Ventana y segundo en el caso de que tuviera quisas el nombre cambie....
En línea

seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: ejecutar un exe, si esta el otro
« Respuesta #5 en: 27 Enero 2011, 05:45 am »

Hola, aca tenes un ejemplo simple de un Hook Global para detectar que ventanas se inician y cierra, activan..etc.

En un Modulo(bas)

Código
  1. Option Explicit
  2.  
  3. Private Declare Function RegisterShellHook Lib "Shell32" Alias "#181" (ByVal hwnd As Long, ByVal nAction As Long) As Long 'use in 98
  4. Private Declare Function RegisterShellHookWindow Lib "user32" (ByVal hwnd As Long) As Long  'use in NT5
  5. Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
  6. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  7. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  8. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  9. Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
  10.  
  11. Private Const HSHELL_WINDOWCREATED = 1
  12. Private Const HSHELL_WINDOWDESTROYED = 2
  13. Private Const HSHELL_ACTIVATESHELLWINDOW = 3
  14. Private Const HSHELL_WINDOWACTIVATED = 4
  15. Private Const HSHELL_GETMINRECT = 5
  16. Private Const HSHELL_REDRAW = 6
  17. Private Const HSHELL_TASKMAN = 7
  18. Private Const HSHELL_LANGUAGE = 8
  19. Private Const HSHELL_SYSMENU = 9
  20. Private Const HSHELL_ENDTASK = 10
  21. Private Const HSHELL_ACCESSIBILITYSTATE = 11
  22. Private Const HSHELL_APPCOMMAND = 12
  23. Private Const HSHELL_WINDOWREPLACED = 13
  24. Private Const HSHELL_WINDOWREPLACING = 14
  25. Private Const HSHELL_HIGHBIT = &H8000
  26. Private Const HSHELL_FLASH = (HSHELL_REDRAW Or HSHELL_HIGHBIT)
  27. Private Const HSHELL_RUDEAPPACTIVATED = (HSHELL_WINDOWACTIVATED Or HSHELL_HIGHBIT)
  28. Private Const GWL_WNDPROC = -4
  29.  
  30. Private Shell_Hook_Msg_ID As Long
  31. Private LogWinOldProc As Long
  32.  
  33. Public Function IniciarHook(ByVal hwnd As Long) As Boolean
  34.    On Error Resume Next
  35.    Dim tmp As Long
  36.    Shell_Hook_Msg_ID = RegisterWindowMessage("SHELLHOOK")
  37.    IniciarHook = Shell_Hook_Msg_ID
  38.    IniciarHook = IniciarHook And (RegisterShellHook(hwnd, 1) Or RegisterShellHookWindow(hwnd))
  39.    LogWinOldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
  40. End Function
  41.  
  42. Public Function DescargarHook(hwnd As Long)
  43.    Call RegisterShellHook(hwnd, 0)
  44.    Call SetWindowLong(hwnd, GWL_WNDPROC, LogWinOldProc)
  45. End Function
  46.  
  47. Private Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long            ' ????
  48.    Dim i As Long
  49.    Dim m_Out_String As String
  50.    Dim recTime As String
  51.    Dim recParam As String
  52.    If uMsg = Shell_Hook_Msg_ID Then
  53.        recTime = Format$(Now(), "YY-MM-DD:HH-NN-SS ") & vbTab & " 0x" & Hex$(wParam) & vbTab & " 0x" & Hex$(lParam) & vbTab & " "
  54.        Select Case wParam
  55.            Case HSHELL_WINDOWCREATED
  56.  
  57.                m_Out_String = String$(260, vbNullChar)
  58.                i = GetWindowText(lParam, m_Out_String, 260)
  59.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  60.                m_Out_String = recTime & "HSHELL_WINDOWCREATED" & vbTab & " " & m_Out_String
  61.                Debug.Print m_Out_String
  62.            Case HSHELL_WINDOWDESTROYED
  63.                m_Out_String = String$(260, vbNullChar)
  64.                i = GetWindowText(lParam, m_Out_String, 260)
  65.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  66.                m_Out_String = recTime & "HSHELL_WINDOWDESTROYED" & vbTab & " " & m_Out_String
  67.                 Debug.Print m_Out_String
  68.            Case HSHELL_ACTIVATESHELLWINDOW
  69.                m_Out_String = recTime & "HSHELL_ACTIVATESHELLWINDOW"
  70.                 Debug.Print m_Out_String
  71.            Case HSHELL_WINDOWACTIVATED
  72.                m_Out_String = String$(260, vbNullChar)
  73.                i = GetWindowText(lParam, m_Out_String, 260)
  74.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  75.                m_Out_String = recTime & "HSHELL_WINDOWACTIVATEED" & vbTab & " " & m_Out_String
  76.                 Debug.Print m_Out_String
  77.            Case HSHELL_GETMINRECT
  78.                m_Out_String = recTime & "HSHELL_GETMINRECT"
  79.            Case HSHELL_REDRAW
  80.                m_Out_String = String$(260, vbNullChar)
  81.                i = GetWindowText(lParam, m_Out_String, 260)
  82.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  83.                m_Out_String = recTime & "HSHELL_REDRAW" & vbTab & " " & m_Out_String
  84.            Case HSHELL_TASKMAN
  85.                m_Out_String = recTime & "HSHELL_TASKMAN"
  86.            Case HSHELL_LANGUAGE
  87.                m_Out_String = recTime & "HSHELL_LANGUAGE"
  88.            Case HSHELL_SYSMENU
  89.                m_Out_String = recTime & "HSHELL_SYSMENU"
  90.            Case HSHELL_ENDTASK
  91.                m_Out_String = String$(260, vbNullChar)
  92.                i = GetWindowText(lParam, m_Out_String, 260)
  93.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  94.                m_Out_String = recTime & "HSHELL_ENDTASK" & vbTab & " " & m_Out_String
  95.            Case HSHELL_ACCESSIBILITYSTATE
  96.                m_Out_String = recTime & "HSHELL_ACCESSIBILITYSTATE"
  97.            Case HSHELL_APPCOMMAND
  98.                m_Out_String = recTime & "HSHELL_APPCOMMAND"
  99.            Case HSHELL_WINDOWREPLACED
  100.                m_Out_String = String$(260, vbNullChar)
  101.                i = GetWindowText(lParam, m_Out_String, 260)
  102.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  103.                m_Out_String = recTime & "HSHELL_WINDOWREPLACED" & vbTab & " " & m_Out_String
  104.            Case HSHELL_WINDOWREPLACING
  105.                m_Out_String = String$(260, vbNullChar)
  106.                i = GetWindowText(lParam, m_Out_String, 260)
  107.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  108.                m_Out_String = recTime & "HSHELL_WINDOWREPLACING" & vbTab & " " & m_Out_String
  109.            Case HSHELL_FLASH
  110.                m_Out_String = String$(260, vbNullChar)
  111.                i = GetWindowText(lParam, m_Out_String, 260)
  112.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  113.                m_Out_String = recTime & "HSHELL_FLASH" & vbTab & " " & m_Out_String
  114.            Case HSHELL_RUDEAPPACTIVATED
  115.                m_Out_String = String$(260, vbNullChar)
  116.                i = GetWindowText(lParam, m_Out_String, 260)
  117.                If i > 0 Then m_Out_String = Left$(m_Out_String, i) Else m_Out_String = "UnNamed"
  118.                m_Out_String = recTime & "HSHELL_RUDEAPPACTIVATEED" & vbTab & " " & m_Out_String
  119.        End Select
  120.  
  121.    Else
  122.        WindowProc = CallWindowProc(LogWinOldProc, hwnd, uMsg, wParam, lParam)
  123.    End If
  124. End Function
  125.  
  126.  

En el Formulario:

Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.    IniciarHook Me.hwnd
  5. End Sub
  6.  
  7. Private Sub Form_Unload(Cancel As Integer)
  8.    DescargarHook Me.hwnd
  9. End Sub

con esto podes detectar por ejemplo cuando se inicia el Notepad, la calculadora..etc.
para eso necesitarias agregarle in FindWindow para sacar el nombre de clase de la ventana y poder validar realmente que se inicio...porque hacerlo por el nombre de la ventana como esta ahora es medio cutre.

saludos.
« Última modificación: 27 Enero 2011, 05:48 am por seba123neo » En línea

agus0


Desconectado Desconectado

Mensajes: 360



Ver Perfil
Re: ejecutar un exe, si esta el otro
« Respuesta #6 en: 27 Enero 2011, 06:52 am »

Con Mi Modulito Necesitas Un Timer...

Ex:

En un Modulo (BAS):

Código
  1. Option Explicit
  2. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  3. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  4. Private Declare Function EnumProcesses Lib "PSAPI.DLL" (lpidProcess As Long, ByVal cb As Long, cbNeeded As Long) As Long
  5. Private Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, lphModule As Long, ByVal cb As Long, lpcbNeeded As Long) As Long
  6. Private Declare Function GetModuleBaseName Lib "PSAPI.DLL" Alias "GetModuleBaseNameA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  7. Private Const PROCESS_VM_READ = &H10
  8. Private Const PROCESS_QUERY_INFORMATION = &H400
  9.  
  10. Public Function EstaCorriendo(ByVal NombreDelProceso As String) As Boolean
  11.    Const MAX_PATH As Long = 260
  12.    Dim lProcesses() As Long, lModules() As Long, N As Long, lRet As Long, hProcess As Long
  13.    Dim sName As String
  14.    NombreDelProceso = UCase$(NombreDelProceso)
  15.    ReDim lProcesses(1023) As Long
  16.  
  17.    If EnumProcesses(lProcesses(0), 1024 * 4, lRet) Then
  18.        For N = 0 To (lRet \ 4) - 1
  19.            hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, lProcesses(N))
  20.            If hProcess Then
  21.                ReDim lModules(1023)
  22.                If EnumProcessModules(hProcess, lModules(0), 1024 * 4, lRet) Then
  23.                    sName = String$(MAX_PATH, vbNullChar)
  24.                    GetModuleBaseName hProcess, lModules(0), sName, MAX_PATH
  25.                    sName = Left$(sName, InStr(sName, vbNullChar) - 1)
  26.  
  27.                    If Len(sName) = Len(NombreDelProceso) Then
  28.                        If NombreDelProceso = UCase$(sName) Then EstaCorriendo = True: Exit Function
  29.                    End If
  30.                End If
  31.            End If
  32.            CloseHandle hProcess
  33.        Next N
  34.    End If
  35. End Function
  36.  
  37.  

en un Form Con 1 Timer


Código
  1. Private Sub Form_Load()
  2.    Timer1.Enabled = True
  3.    Timer1.Interval = 100
  4.    Me.BackColor = vbRed
  5. End Sub
  6.  
  7. Private Sub Timer1_Timer()
  8.    If EstaCorriendo("calc.exe") Then
  9.        Me.BackColor = vbGreen
  10.    Else
  11.        Me.BackColor = vbRed
  12.    End If
  13. End Sub
  14.  
  15.  

En Mi Ejemplo Si la Calculadora de Windows esta Avierta el Fondo del Formulario Se Vuelve Verde si La Calculadora (Proceso "calc.exe") esta Cerrada el Form Queda Color Rojo...
En línea

Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: ejecutar un exe, si esta el otro
« Respuesta #7 en: 27 Enero 2011, 09:03 am »

Está interesante tu código seba123neo!

@agus0
Al menos pon la fuente : http://www.vbforums.com/showpost.php?p=2748682&postcount=2

DoEvents! :P
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: ejecutar un exe, si esta el otro
« Respuesta #8 en: 27 Enero 2011, 10:26 am »

.
Ajale hace tiempo que no veo el codigo de barenx que publico Seba123Neo.

Edito:

Si no me equivoco WParam te retorna el handle de la ventana así ya no tienes que usar FindWindow, exentando los siguientes mensajes que difieren:

 * HSHELL_ACCESSIBILITYSTATE
 * HSHELL_APPCOMMAND


Con saber el handle de una ventana puedes identificar todo rastreando.

Más info en: ShellProc Callback Function

P.D.: Es casi lo mismo con WH_CBT ( Esta en C/C++) MSDN.

Dulces Lunas!¡.
« Última modificación: 27 Enero 2011, 10:41 am por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
agus0


Desconectado Desconectado

Mensajes: 360



Ver Perfil
Re: ejecutar un exe, si esta el otro
« Respuesta #9 en: 28 Enero 2011, 06:20 am »

Está interesante tu código seba123neo!

@agus0
Al menos pon la fuente : http://www.vbforums.com/showpost.php?p=2748682&postcount=2

DoEvents! :P

Gracias Mr.Frog por poner la Fuente. La Verdad que este Codigo lo tengo guardado desde hace un par de años y no tenia ni idea de donde lo saque por eso no la Cite a la Fuente...
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
como ejecutar una aplicacion con componente winsock en otro computador
Programación Visual Basic
miguelangel 3 3,476 Último mensaje 8 Junio 2005, 14:17 pm
por
como poder ejecutar desde otro dvd
Juegos y Consolas
cmcmc 0 1,419 Último mensaje 9 Mayo 2006, 12:11 pm
por cmcmc
Problema al ejecutar mi troyano en otro pc
Programación Visual Basic
chorl41a 6 2,176 Último mensaje 1 Octubre 2008, 23:56 pm
por Spider-Net
Ejecutar un .bat e red que ejecute otro .bat
Scripting
Oriens 9 9,072 Último mensaje 14 Marzo 2016, 13:58 pm
por Oriens
Ejecutar BAT en otro PC
Scripting
branon32 2 2,133 Último mensaje 8 Diciembre 2018, 09:20 am
por branon32
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines