vb.net 电脑关机事件?网络
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14376605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:54:52 来源:igfitidea点击:
Computer Shutdown event ? VB.NET
提问by user1970090
Possible Duplicate:
Detecting windows shutdown event
可能的重复:
检测 Windows 关闭事件
Is there is any event about shutting down in VB.NET ? I want to execute statement when the computer the user clicks shut down , can this be done in vb.net ?
是否有关于在 VB.NET 中关闭的任何事件?我想在用户单击关闭的计算机时执行语句,这可以在 vb.net 中完成吗?
回答by John Sibly
Example from here
从这里的例子
Public Class Form1
Private Sub Form1_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

