我尝试在检测到关机或注销时显示一些 MsgBox .. 比如“你正在注销..
Public Class frmDetectEnd
Private Sub frmDetectEnd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf Handler_SessionEnding
End Sub
Public Sub Handler_SessionEnding(ByVal sender As Object, ByVal e As Microsoft.Win32.SessionEndingEventArgs)
If e.Reason = Microsoft.Win32.SessionEndReasons.Logoff Then
MessageBox.Show("User is logging off")
ElseIf e.Reason = Microsoft.Win32.SessionEndReasons.SystemShutdown Then
MessageBox.Show("System is shutting down")
End If
End Sub
End Class
此检测工作正常,但如果显示 MsgBox,我想停止关机/注销过程,因为此时执行关机/注销过程并停止并显示 Windows 消息“此程序正在阻止您注销...”。
但是,我希望在收到消息“用户正在登录/系统正在关闭”后,用户可以选择命令按钮来处理某些事情,然后关闭或注销可以继续。