Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computer Shutdown event ? VB.NET [duplicate]

Possible Duplicate:
Detecting windows shutdown event

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 ?

like image 664
user1970090 Avatar asked Jan 17 '13 10:01

user1970090


1 Answers

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
like image 194
John Sibly Avatar answered Oct 03 '22 20:10

John Sibly