Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: igustin en 5 Marzo 2013, 07:43 am



Título: KeyLogger (Por decirle de una manera)
Publicado por: igustin en 5 Marzo 2013, 07:43 am
Vengo haciendo un "KeyLogger" y  lo quiero lograr es que al clickiar una ventana me diga su nombre en el .txt que ya he creado. Lo logre :D pero al tiepo de depurarlo me salta un error:


Título: Re: KeyLogger (Por decirle de una manera)
Publicado por: igustin en 5 Marzo 2013, 07:51 am
Public Class Form1
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Y he añadido la Private Function:
    Private Function GetActiveWindowTitle() As String
        Dim MyStr As String
        MyStr = New String(Chr(0), 100)
        GetWindowText(GetForeGroundWindow, MyStr, 100)
        MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
        Return MyStr
    End Function

Pero al tiempo de depurarlo me sale el siguente error:
En:
GetWindowText (Getforegroundwin-dow, mystr, 100)
El mesaje:
Unable to find an entry point named 'GetForegroundWindow' in DLL 'user32.dll'.
please in charge

Alguien sabe porque?? Soy novato y como ven he creado el post varias veces porque he trato de adjuntarlo a las etiquetas, las cuales no he encontrado todavia.


Título: Re: KeyLogger (Por decirle de una manera)
Publicado por: crifesma en 28 Marzo 2013, 15:38 pm
con poco conocimiento que tengo, creo que deberías haber hecho la misma declaración para ambas funciones


Título: Re: KeyLogger (Por decirle de una manera)
Publicado por: Crazy.sx en 29 Marzo 2013, 04:33 am
Hola, mirá. Yo también hice un keylogger con todos los "chiches" y me funciona de lo más bien. Aquí te dejo una clase que hice para capturar el nombre de la ventana activa.

Espero que te sirva:

Código
  1. Public Class VentanaActiva
  2. #Region " Declaraciones del API de Win32 "
  3.    '
  4.    <System.Runtime.InteropServices.DllImport("user32.dll")> _
  5.    Private Shared Function GetWindowText( _
  6.        ByVal hWnd As System.IntPtr, _
  7.        ByVal lpString As System.Text.StringBuilder, _
  8.        ByVal cch As Integer) As Integer
  9.    End Function
  10.    '
  11.    <System.Runtime.InteropServices.DllImport("user32.dll")> _
  12.    Private Shared Function GetActiveWindow() As System.IntPtr
  13.    End Function
  14.    '
  15.    <System.Runtime.InteropServices.DllImport("user32.dll")> _
  16.    Private Shared Function GetForegroundWindow() As System.IntPtr
  17.    End Function
  18.    '
  19. #End Region
  20.    Dim vRetorno As String
  21.    Public Function CapturaVentana()
  22.  
  23.        ' r
  24.        Dim titulo As New System.Text.StringBuilder(New String(" "c, 256))
  25.        Dim ret As Integer
  26.        Dim nombreVentana As String
  27.  
  28.        Dim hWnd As IntPtr = GetForegroundWindow()
  29.        '
  30.        'If hWnd.Equals(IntPtr.Zero) Then Return
  31.        '
  32.        ret = GetWindowText(hWnd, titulo, titulo.Length)
  33.        'If ret = 0 Then Return
  34.        '
  35.        nombreVentana = titulo.ToString.Substring(0, ret)
  36.        If nombreVentana <> Nothing AndAlso nombreVentana.Length > 0 Then
  37.  
  38.            vRetorno = nombreVentana + "[" + DateTime.Now.ToString("HH:mm:ss") + "] "
  39.  
  40.        End If
  41.  
  42.        Return vRetorno
  43.    End Function
  44.  
  45.  
  46. End Class

Saludos.


Título: Re: KeyLogger (Por decirle de una manera)
Publicado por: Eleкtro en 3 Abril 2013, 19:42 pm
Eso es lo que pasa por querer hacer las cosas con un Copy/Paste de códigos antiguos de Windows XP o de VB6 xD.

El error es que estás usando el tipo Long, modifica todos los Long por Integer, y listo, funciona.

Saludos!