Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15079

Detect Windows 10 Shutdown Event

$
0
0
Hi everyone,

I have an application that is designed to interrupt FormClosing with e.cancel = True to prevent the application from ending when user closes a window. I use a notifyicon so users can click on the icon to bring it back. I have used WndProc in the past to trigger an End event when Windows Shutdown, Restart or Log Off is detected. Works well on XP, hit or miss with Windows 7 but not working with Windows 10. When I shut down, Windows will just say my application is preventing the shutdown process.

My WndProc code looks like this but I'm not the author of this snippet:
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


How do you detect a Windows shutdown event on Windows 10 (64-bit)? Anyone else having problems with .Net applications causing a Shutdown/Restart process to halt? Thanks everyone!

Viewing all articles
Browse latest Browse all 15079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>