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

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  listar nombre de ventana de los procesos. No lo consigo.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: listar nombre de ventana de los procesos. No lo consigo.  (Leído 2,609 veces)
70N1


Desconectado Desconectado

Mensajes: 355


Ver Perfil
listar nombre de ventana de los procesos. No lo consigo.
« en: 10 Marzo 2009, 14:24 pm »

Tengo ese problema, no consigo listar los nombres de las ventanas de los procesos

e intentado con:

Código:
dim recogidadedatos as string, handle as long
handle=openprocess( information or read,0, id)
getwindowtext(handle,recogidadedatos,100)
msgbox(recogidadedatos)

Pero parece que no encuentra el handle. Alguien me puede explicar el motivo?

A ¡¡, En el proceso vb leido con openprocess me da un handle pero en otro programa me sale otro handle en el mismo proceso.

Este es el modulo que lista los procesos en un treeview y pone en handle el classname y las dependencias:
Código:
Public Function FillProcessListNT(treeview As MSComctlLib.treeview) As Long
    '=========================================================
    'Clears the listbox specified by the DestListBox parameter
    'and then fills the list with the processes and the
    'modules used by each process
    '=========================================================

    Dim cb                  As Long
    Dim cbNeeded            As Long
    Dim NumElements         As Long
    Dim ProcessIDs()        As Long
    Dim cbNeeded2           As Long
    Dim NumElements2        As Long
    Dim Modules(1 To 1024)  As Long
    Dim lRet                As Long
    Dim ModuleName          As String
    Dim nSize               As Long
    Dim hProcess            As Long
    Dim i                   As Long
    Dim sModName            As String
    Dim sChildModName       As String
    Dim iModDlls            As Long
    Dim iProcesses          As Integer
    Dim nodo(5)             As Node
   
   
    treeview.Nodes.Clear
     
     Set nodo(0) = treeview.Nodes.Add(, , , "Procesos en ejecucion")
               
    'Get the array containing the process id's for each process object
    cb = 8
    cbNeeded = 96
   
    'One important note should be made. Although the documentation
    'names the returned DWORD "cbNeeded", there is actually no way
    'to find out how big the passed in array must be. EnumProcesses()
    'will never return a value in cbNeeded that is larger than the
    'size of array value that you passed in the cb parameter.
   
    'if cbNeeded == cb upon return, allocate a larger array
    'and try again until cbNeeded is smaller than cb.
    Do While cb <= cbNeeded
       cb = cb * 2
       ReDim ProcessIDs(cb / 4) As Long
       lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
    Loop
   
    'calculate how many process IDs were returned
    NumElements = cbNeeded / 4
   
    For i = 1 To NumElements
   
        'Get a handle to the Process
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
            Or PROCESS_VM_READ, 0, ProcessIDs(i))

        ' Iterate through each process with an ID that <> 0
        If hProcess Then
           
            'Retrieve the number of bytes that the array of module handles requires
            lRet = EnumProcessModules(hProcess, Modules(1), 1024, cbNeeded2)
            'Get an array of the module handles for the specified process
            lRet = EnumProcessModules(hProcess, Modules(1), cbNeeded2, cbNeeded2)
           
            'If the Module Array is retrieved, Get the ModuleFileName
            If lRet <> 0 Then
               
                'Fill the ModuleName buffer with spaces
                ModuleName = Space(MAX_PATH)
               
                'Preset buffer size
                nSize = 500
               
                'Get the module file name
                lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, nSize)
                frmModuleList.Text1.Text = Modules(1)
                'Get the module file name out of the buffer, lRet is how
                'many characters the string is, the rest of the buffer is spaces
                sModName = Left$(ModuleName, lRet)
               
                'Add the process to the listbox
                Set nodo(1) = treeview.Nodes.Add(nodo(0), tvwChild, , sModName, "false")
               
               treeview.Nodes.Add nodo(1), tvwChild, , "Class name :"
               treeview.Nodes.Add nodo(1), tvwChild, , "Pid :" & ProcessIDs(i)
                       treeview.Nodes.Add nodo(1), tvwChild, , "Hwnd :" & hProcess
                Set nodo(2) = treeview.Nodes.Add(nodo(1), tvwChild, , "Dependencias")
             
                'Increment the count of processes we've added
                iProcesses = iProcesses + 1
               
                iModDlls = 1
                Do
                    iModDlls = iModDlls + 1
                   
                    'Fill the ModuleName buffer with spaces
                    ModuleName = Space(MAX_PATH)
                   
                    'Preset buffer size
                    nSize = 500
                   
                    'Get the module file name out of the buffer, lRet is how
                    'many characters the string is, the rest of the buffer is spaces
                    lRet = GetModuleFileNameExA(hProcess, Modules(iModDlls), ModuleName, nSize)
                    sChildModName = Left$(ModuleName, lRet)
                   
                    If sChildModName = sModName Then Exit Do
                    If Trim(sChildModName) <> "" Then treeview.Nodes.Add nodo(2), tvwChild, , sChildModName, "false"
                Loop
            End If
        Else
            'Return the number of Processes found
            FillProcessListNT = 0
        End If
       
        'Close the handle to the process
        lRet = CloseHandle(hProcess)
    Next
   
    'Return the number of Processes found
    FillProcessListNT = iProcesses
   
End Function



« Última modificación: 10 Marzo 2009, 15:14 pm por 70N1 » En línea

70N1
Dessa


Desconectado Desconectado

Mensajes: 624



Ver Perfil
Re: listar nombre de ventana de los procesos. No lo consigo.
« Respuesta #1 en: 10 Marzo 2009, 17:36 pm »

Pero parece que no encuentra el handle. Alguien me puede explicar el motivo?

A ¡¡, En el proceso vb leido con openprocess me da un handle pero en otro programa me sale otro handle en el mismo proceso.


El handle que usas para abrir un proceso (openprocess) es el PID o ID del proceso.

Este Handle_Proceso no es mismo handle de las ventanas (aplicaciones) que se enumeran con EnumWindows   



En línea

Adrian Desanti
seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: listar nombre de ventana de los procesos. No lo consigo.
« Respuesta #2 en: 11 Marzo 2009, 04:02 am »

Hola, aca te paso un codigo que me parecio bueno para lo que queres, despues modificalo vos para lo que realmente necesitas, lo que hace es listarte las todas las ventanas..con su HWND, nombre de clase y caption de la ventana...y al hacer click accedes tambien a las Ventanas Hijas...necesitas 2 listview , 1 check, y un boton...ponelos asi nomas con las propiedades por defecto y despues pega este codigo...el checkbox sirve para elegir si queres listar todas las ventanas del sistema o solo las que tienen caption...

En un Modulo:

Código
  1. Option Explicit
  2.  
  3. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  4. Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  5. Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
  6. Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long
  7. Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  8. Public Declare Function EnumChildWindows Lib "user32" (ByVal hwndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long
  9.  
  10. Public Const WM_GETTEXT = &HD
  11. Public Const WM_GETTEXTLENGTH = &HE
  12. Public Const EM_GETPASSWORDCHAR = &HD2
  13.  
  14. Public VCount As Integer, ICount As Integer
  15.  
  16. Public Function WndEnumProc(ByVal hwnd As Long, ByVal lParam As ListView) As Long
  17.    Dim WText As String * 512
  18.    Dim bRet As Long, WLen As Long
  19.    Dim WClass As String * 50
  20.  
  21.    WLen = GetWindowTextLength(hwnd)
  22.    bRet = GetWindowText(hwnd, WText, WLen + 1)
  23.    GetClassName hwnd, WClass, 50
  24.  
  25.    With Form1
  26.        If (.Check1.Value = vbUnchecked) Then
  27.            Insertar hwnd, lParam, WText, WClass
  28.        ElseIf (.Check1.Value = vbChecked And WLen <> 0) Then
  29.            Insertar hwnd, lParam, WText, WClass
  30.        End If
  31.    End With
  32.  
  33.    WndEnumProc = 1
  34. End Function
  35.  
  36. Private Sub Insertar(iHwnd As Long, lParam As ListView, iText As String, iClass As String)
  37.    lParam.ListItems.Add.Text = Str(iHwnd)
  38.    lParam.ListItems.Item(VCount).SubItems(1) = iClass
  39.    lParam.ListItems.Item(VCount).SubItems(2) = iText
  40.    VCount = VCount + 1
  41. End Sub
  42.  
  43. Public Function WndEnumChildProc(ByVal hwnd As Long, ByVal lParam As ListView) As Long
  44.    Dim bRet As Long
  45.    Dim myStr As String * 50
  46.    bRet = GetClassName(hwnd, myStr, 50)
  47.    With lParam.ListItems
  48.        .Add.Text = Str(hwnd)
  49.        .Item(ICount).SubItems(1) = myStr
  50.        .Item(ICount).SubItems(2) = GetText(hwnd)
  51.        If SendMessage(hwnd, EM_GETPASSWORDCHAR, 0, 0) = 0 Then
  52.            .Item(ICount).SubItems(3) = "NO"
  53.        Else
  54.            .Item(ICount).SubItems(3) = "SI"
  55.            .Item(ICount).ForeColor = vbRed
  56.            .Item(ICount).Bold = True
  57.            .Item(ICount).ListSubItems.Item(1).ForeColor = vbRed
  58.            .Item(ICount).ListSubItems.Item(1).Bold = True
  59.            .Item(ICount).ListSubItems.Item(2).ForeColor = vbRed
  60.            .Item(ICount).ListSubItems.Item(2).Bold = True
  61.            .Item(ICount).ListSubItems.Item(3).ForeColor = vbRed
  62.            .Item(ICount).ListSubItems.Item(3).Bold = True
  63.        End If
  64.    End With
  65.    ICount = ICount + 1
  66.    WndEnumChildProc = 1
  67. End Function
  68.  
  69. Function GetText(iHwnd As Long) As String
  70.    Dim Textlen As Long
  71.    Dim Text As String
  72.    Textlen = SendMessage(iHwnd, WM_GETTEXTLENGTH, 0, 0)
  73.    If Textlen = 0 Then
  74.        GetText = "No se encontro Texto..."
  75.        Exit Function
  76.    End If
  77.    Textlen = Textlen + 1
  78.    Text = Space(Textlen)
  79.    Textlen = SendMessage(iHwnd, WM_GETTEXT, Textlen, ByVal Text)
  80.    GetText = Left(Text, Textlen)
  81. End Function

En el Formulario:

Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.    Command1.Caption = "Listar Ventanas"
  5.    Check1.Caption = "Solo Ventanas con Caption"
  6.    Call ConfiguraListview
  7. End Sub
  8.  
  9. Private Sub ConfiguraListview()
  10.    ListView1.View = lvwReport
  11.    ListView1.FullRowSelect = True
  12.    ListView2.FullRowSelect = True
  13.    With ListView1.ColumnHeaders
  14.        .Add , , "HWND", 1000
  15.        .Add , , "Nombre de Clase", 1500
  16.        .Add , , "Caption Ventana", 3000
  17.    End With
  18.    VCount = 1
  19.    ListView2.View = lvwReport
  20.    With ListView2.ColumnHeaders
  21.        .Add , , "HWND", 1000
  22.        .Add , , "Nombre de Clase", 1500
  23.        .Add , , "Caption Ventana", 2500
  24.        .Add , , "Textbox de Password", 1500
  25.    End With
  26.    ICount = 1
  27. End Sub
  28.  
  29. Private Sub Command1_Click()
  30.    ListView1.ListItems.Clear
  31.    ListView2.ListItems.Clear
  32.    ListView1.GridLines = True
  33.    VCount = 1
  34.    EnumWindows AddressOf WndEnumProc, ListView1
  35. End Sub
  36.  
  37. Private Sub Listview1_Click()
  38.    Call ListarHijas
  39. End Sub
  40.  
  41. Private Sub ListarHijas()
  42. On Error Resume Next
  43.    Dim Numero As Long
  44.    Numero = Val(ListView1.SelectedItem)
  45.    ListView2.ListItems.Clear
  46.    ListView2.GridLines = True
  47.    ICount = 1
  48.    EnumChildWindows Numero, AddressOf WndEnumChildProc, ListView2
  49. End Sub
  50.  

saludos.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[VB.NET] Listar procesos activos en un Listbox.
.NET (C#, VB.NET, ASP)
kub0x 2 4,814 Último mensaje 26 Agosto 2011, 04:09 am
por kub0x
Listar Procesos
Programación Visual Basic
calk9 4 2,590 Último mensaje 20 Diciembre 2011, 00:52 am
por calk9
Listar puertos en uso por procesos
Programación Visual Basic
vvictoristudio 2 1,946 Último mensaje 18 Diciembre 2013, 10:34 am
por Mad Antrax
Qt listar procesos | Qt eliminar objetos
Programación C/C++
patilanz 4 3,041 Último mensaje 15 Noviembre 2014, 15:54 pm
por patilanz
Listar procesos y rutas en ListBox
.NET (C#, VB.NET, ASP)
dust564 3 2,933 Último mensaje 7 Junio 2015, 09:43 am
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines