关于SystemEvents.SessionSwitch的问题不调用

时间:2019-06-26 10:39:12

标签: vb.net event-handling addeventlistener

SystemEvents.SessionSwitch在EXE文件中时未调用此处理程序,但在VS中调用并工作为TRUE

AddHandler SystemEvents.SessionSwitch,AddressOf SystemEvents_SessionSwitch

Public Sub SystemEvents_SessionSwitch(ByVal sender As Object, ByVal e As SessionSwitchEventArgs)
    Console.Write("Event" + vbNewLine)
    Dim messageInfo As String = String.Empty
    Select Case (e.Reason)
        Case SessionSwitchReason.SessionLock
            messageInfo = "Your computer Locked at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.SessionLogoff
            messageInfo = "Your computer Logoff at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.SessionLogon
            messageInfo = "Your computer Logon at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.SessionUnlock
            messageInfo = "Your computer Unlock at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.ConsoleConnect
            messageInfo = "A session has been connected from the console at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.ConsoleDisconnect
            messageInfo = "A session has been disconnected from the console at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.RemoteConnect
            messageInfo = "A session has been connected from a remote connection at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.RemoteDisconnect
            messageInfo = "A session has been disconnected from a remote connection at {0:yyyy-MM-dd HH:mm:ss} by {1}."
        Case SessionSwitchReason.SessionRemoteControl
            messageInfo = "A session has changed its status to or from remote controlled mode at {0:yyyy-MM-dd HH:mm:ss} by {1}." &
            ""
    End Select

    If (messageInfo <> String.Empty) Then
        Console.Write(String.Format(messageInfo, getDatePersian(), GetLoginUserName))
    Else
        Console.Write(String.Format(messageInfo, getDatePersian(), GetLoginUserName))
    End If

End Sub

0 个答案:

没有答案