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

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Sobre los child handles
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Sobre los child handles  (Leído 2,231 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.878



Ver Perfil
Sobre los child handles
« en: 9 Abril 2013, 19:54 pm »

Necesito listar todos los handles hijos de un proceso, para eso utilizo esta Class: http://kellyschronicles.wordpress.com/2008/06/23/get-window-handles-associated-with-process-in-vb-net/

Código
  1. Imports System.Collections.Generic
  2. Imports System.Runtime.InteropServices
  3. Imports System.Text
  4.  
  5. Public Class ApiWindow
  6.    Public MainWindowTitle As String = ""
  7.    Public ClassName As String = ""
  8.    Public hWnd As Int32
  9. End Class
  10.  
  11. ''' <summary>
  12. ''' Enumerate top-level and child windows
  13. ''' </summary>
  14. ''' <example>
  15. ''' Dim enumerator As New WindowsEnumerator()
  16. ''' For Each top As ApiWindow in enumerator.GetTopLevelWindows()
  17. '''    Console.WriteLine(top.MainWindowTitle)
  18. '''    For Each child As ApiWindow child in enumerator.GetChildWindows(top.hWnd)
  19. '''        Console.WriteLine(" " + child.MainWindowTitle)
  20. '''    Next child
  21. ''' Next top
  22. ''' </example>
  23. Public Class WindowsEnumerator
  24.  
  25.    Private Delegate Function EnumCallBackDelegate(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
  26.  
  27.    ' Top-level windows.
  28.    Private Declare Function EnumWindows Lib "user32" _
  29.     (ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As Integer
  30.  
  31.    ' Child windows.
  32.    Private Declare Function EnumChildWindows Lib "user32" _
  33.     (ByVal hWndParent As Integer, ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As Integer
  34.  
  35.    ' Get the window class.
  36.    Private Declare Function GetClassName _
  37.     Lib "user32" Alias "GetClassNameA" _
  38.     (ByVal hwnd As Integer, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
  39.  
  40.    ' Test if the window is visible--only get visible ones.
  41.    Private Declare Function IsWindowVisible Lib "user32" _
  42.     (ByVal hwnd As Integer) As Integer
  43.  
  44.    ' Test if the window's parent--only get the one's without parents.
  45.    Private Declare Function GetParent Lib "user32" _
  46.     (ByVal hwnd As Integer) As Integer
  47.  
  48.    ' Get window text length signature.
  49.    Private Declare Function SendMessage _
  50.     Lib "user32" Alias "SendMessageA" _
  51.     (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
  52.  
  53.    ' Get window text signature.
  54.    Private Declare Function SendMessage _
  55.     Lib "user32" Alias "SendMessageA" _
  56.     (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As StringBuilder) As Int32
  57.  
  58.    Private _listChildren As New List(Of ApiWindow)
  59.    Private _listTopLevel As New List(Of ApiWindow)
  60.  
  61.    Private _topLevelClass As String = ""
  62.    Private _childClass As String = ""
  63.  
  64.    ''' <summary>
  65.    ''' Get all top-level window information
  66.    ''' </summary>
  67.    ''' <returns>List of window information objects</returns>
  68.    Public Overloads Function GetTopLevelWindows() As List(Of ApiWindow)
  69.  
  70.        EnumWindows(AddressOf EnumWindowProc, &H0)
  71.  
  72.        Return _listTopLevel
  73.  
  74.    End Function
  75.  
  76.    Public Overloads Function GetTopLevelWindows(ByVal className As String) As List(Of ApiWindow)
  77.  
  78.        _topLevelClass = className
  79.  
  80.        Return Me.GetTopLevelWindows()
  81.  
  82.    End Function
  83.  
  84.    ''' <summary>
  85.    ''' Get all child windows for the specific windows handle (hwnd).
  86.    ''' </summary>
  87.    ''' <returns>List of child windows for parent window</returns>
  88.    Public Overloads Function GetChildWindows(ByVal hwnd As Int32) As List(Of ApiWindow)
  89.  
  90.        ' Clear the window list.
  91.        _listChildren = New List(Of ApiWindow)
  92.  
  93.        ' Start the enumeration process.
  94.        EnumChildWindows(hwnd, AddressOf EnumChildWindowProc, &H0)
  95.  
  96.        ' Return the children list when the process is completed.
  97.        Return _listChildren
  98.  
  99.    End Function
  100.  
  101.    Public Overloads Function GetChildWindows(ByVal hwnd As Int32, ByVal childClass As String) As List(Of ApiWindow)
  102.  
  103.        ' Set the search
  104.        _childClass = childClass
  105.  
  106.        Return Me.GetChildWindows(hwnd)
  107.  
  108.    End Function
  109.  
  110.    ''' <summary>
  111.    ''' Callback function that does the work of enumerating top-level windows.
  112.    ''' </summary>
  113.    ''' <param name="hwnd">Discovered Window handle</param>
  114.    ''' <returns>1=keep going, 0=stop</returns>
  115.    Private Function EnumWindowProc(ByVal hwnd As Int32, ByVal lParam As Int32) As Int32
  116.  
  117.        ' Eliminate windows that are not top-level.
  118.        If GetParent(hwnd) = 0 AndAlso CBool(IsWindowVisible(hwnd)) Then
  119.  
  120.            ' Get the window title / class name.
  121.            Dim window As ApiWindow = GetWindowIdentification(hwnd)
  122.  
  123.            ' Match the class name if searching for a specific window class.
  124.            If _topLevelClass.Length = 0 OrElse window.ClassName.ToLower() = _topLevelClass.ToLower() Then
  125.                _listTopLevel.Add(window)
  126.            End If
  127.  
  128.        End If
  129.  
  130.        ' To continue enumeration, return True (1), and to stop enumeration
  131.        ' return False (0).
  132.        ' When 1 is returned, enumeration continues until there are no
  133.        ' more windows left.
  134.  
  135.        Return 1
  136.  
  137.    End Function
  138.  
  139.    ''' <summary>
  140.    ''' Callback function that does the work of enumerating child windows.
  141.    ''' </summary>
  142.    ''' <param name="hwnd">Discovered Window handle</param>
  143.    ''' <returns>1=keep going, 0=stop</returns>
  144.    Private Function EnumChildWindowProc(ByVal hwnd As Int32, ByVal lParam As Int32) As Int32
  145.  
  146.        Dim window As ApiWindow = GetWindowIdentification(hwnd)
  147.  
  148.        ' Attempt to match the child class, if one was specified, otherwise
  149.        ' enumerate all the child windows.
  150.        If _childClass.Length = 0 OrElse window.ClassName.ToLower() = _childClass.ToLower() Then
  151.            _listChildren.Add(window)
  152.        End If
  153.  
  154.        Return 1
  155.  
  156.    End Function
  157.  
  158.    ''' <summary>
  159.    ''' Build the ApiWindow object to hold information about the Window object.
  160.    ''' </summary>
  161.    Private Function GetWindowIdentification(ByVal hwnd As Integer) As ApiWindow
  162.  
  163.        Const WM_GETTEXT As Int32 = &HD
  164.        Const WM_GETTEXTLENGTH As Int32 = &HE
  165.  
  166.        Dim window As New ApiWindow()
  167.  
  168.        Dim title As New StringBuilder()
  169.  
  170.        ' Get the size of the string required to hold the window title.
  171.        Dim size As Int32 = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)
  172.  
  173.        ' If the return is 0, there is no title.
  174.        If size > 0 Then
  175.            title = New StringBuilder(size + 1)
  176.  
  177.            SendMessage(hwnd, WM_GETTEXT, title.Capacity, title)
  178.        End If
  179.  
  180.        ' Get the class name for the window.
  181.        Dim classBuilder As New StringBuilder(64)
  182.        GetClassName(hwnd, classBuilder, 64)
  183.  
  184.        ' Set the properties for the ApiWindow object.
  185.        window.ClassName = classBuilder.ToString()
  186.        window.MainWindowTitle = title.ToString()
  187.        window.hWnd = hwnd
  188.  
  189.        Return window
  190.  
  191.    End Function
  192.  
  193. End Class


Y la uso de esta manera, pero solo obtengo el "main" handle:

Código
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.    Dim enumerator As New WindowsEnumerator()
  3.    For Each top As ApiWindow In enumerator.GetTopLevelWindows()
  4.        If top.MainWindowTitle.ToLower.Contains("firefox") Then
  5.            RichTextBox1.Text += vbNewLine & ("main handle: " & top.MainWindowTitle)
  6.            For Each child As ApiWindow In enumerator.GetChildWindows(top.hWnd)
  7.                RichTextBox1.Text += vbNewLine & ("child handle: " & " " + child.MainWindowTitle)
  8.            Next
  9.        End If
  10.    Next top
  11.  
  12. End Sub

Así que algo está mal.

Lo que quiero es obtener todos los handles de un proceso, como por ejemplo el output que nos da la utilidad CommandLine "CMDOW" con este comando:

Código:
C:\>cmdow | find /i "firefox"

Código:
0x2C0242 1  912 Res Ina Ena Hid firefox  Code Sample <pre><code> Ctrl+K
0x1F0C10 1  912 Res Ina Ena Hid firefox  pinvoke.net: EnumWindowsProc (Delegate
0x6E06A8 1  912 Res Ina Ena Hid firefox  MozillaDropShadowWindowClass
0x310ADA 1  912 Res Ina Ena Hid firefox  MozillaDropShadowWindowClass
0x610D3A 1  912 Res Ina Ena Hid firefox  MozillaWindowClass
0x840A54 1  912 Res Ina Ena Hid firefox  MozillaDropShadowWindowClass
0x9A08D6 1  912 Res Ina Ena Hid firefox  Search using Google (English)
0x17E057C 1  912 Res Ina Ena Hid firefox  MozillaDropShadowWindowClass
0x2E0A5A 1  912 Res Ina Ena Hid firefox  MozillaWindowClass
0x4A04DC 1  912 Min Ina Ena Vis firefox  Get all child handles of process - Sta
0xA40994 1  912 Min Ina Ena Hid firefox  pinvoke.net: EnumWindowsProc (Delegate
0x110CF4 1  912 Min Ina Ena Hid firefox  pinvoke.net: EnumChildWindows (user32)
0x560270 1  912 Min Ina Ena Hid firefox  Get handles of process forms c# - Stac
0x7B0CCC 1  912 Min Ina Ena Hid firefox  Get child window handles in C# - Stack
0x74040A 1  912 Min Ina Ena Hid firefox  Get all child handles of process - Sta
0xC0028A 1  912 Min Ina Ena Hid firefox  Get Window Handles Associated With Pro
0xAC067C 1  912 Min Ina Ena Hid firefox  vbnet get child handles of process - B
0x6308B0 1  912 Min Ina Ena Hid firefox  Process Class (System.Diagnostics) - M
0xB20B2E 1  912 Min Ina Ena Hid firefox  How to wait the process until the proc
0xA7021C 1  912 Min Ina Ena Hid firefox  vb.net - Waiting For Process To Comple
0xD30356 1  912 Min Ina Ena Hid firefox  FreeVBCode code snippet: Execute a Pro
0x583207D0 1  912 Res Ina Ena Hid firefox  nsAppShell:EventWindow
0x3C0550 1  912 Res Ina Ena Hid firefox  DDEMLEvent
0x3E065C 1  912 Res Ina Ena Hid firefox  DDEMLMom
0x590288 1  912 Res Ina Ena Hid firefox  FirefoxMessageWindow
0x2D085A 1  912 Min Ina Ena Hid firefox  vbnet wait for process end - Buscar co
0x5F0584 1  912 Res Ina Ena Hid firefox  MCI command handling window
0x2307D2 1  912 Res Ina Ena Hid firefox  MozillaHiddenWindowClass
0x1760466 1  912 Res Ina Dis Hid firefox  MSCTFIME UI
0x200CB4 1  912 Res Ina Dis Hid firefox  Default IME
0x510320 1  912 Res Ina Dis Hid firefox  Default IME


En línea



Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
hacer un listado de handles que usa una aplicacion
Programación Visual Basic
capblack 2 1,470 Último mensaje 27 Julio 2005, 01:22 am
por capblack
Obtener handles de ficheros asociados a un proceso
.NET (C#, VB.NET, ASP)
mmob 8 5,669 Último mensaje 17 Diciembre 2007, 17:43 pm
por mmob
Handles (VB.NET)
.NET (C#, VB.NET, ASP)
abreu20011 4 8,932 Último mensaje 27 Agosto 2011, 03:20 am
por Keyen Night
Modificar MDI desde un Child (vb.net 2003)
.NET (C#, VB.NET, ASP)
Dreamcacher 2 2,963 Último mensaje 25 Enero 2012, 18:08 pm
por Dreamcacher
Sobre los Handles del SystemTray...
.NET (C#, VB.NET, ASP)
Eleкtro 0 1,805 Último mensaje 9 Abril 2013, 19:48 pm
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines