Click here to Skip to main content
15,880,299 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi!
I want to write a code while shutting windows down.
I mean if the windows is going to shut down and my app still working, it does something and then close the app and shut down

thanks
Posted

1 solution

Try this:

VB.NET
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

 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf Handler_SessionEnding
    End Sub 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900