-
Sep 2nd, 2020, 08:27 AM
#1
Thread Starter
Junior Member
Detect Windows 10 Shutdown Event
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!
-
Sep 2nd, 2020, 12:26 PM
#2
Re: Detect Windows 10 Shutdown Event
-
Sep 2nd, 2020, 01:13 PM
#3
Thread Starter
Junior Member
-
Sep 2nd, 2020, 01:20 PM
#4
Re: Detect Windows 10 Shutdown Event
You’re welcome. Yes, it is old. Perhaps it could be updated?
-
Sep 2nd, 2020, 01:24 PM
#5
Thread Starter
Junior Member
Re: Detect Windows 10 Shutdown Event
I was trying to look for a new version for 64-bit Windows but I couldn't find it. My software was originally written for Windows XP. The code you shared worked flawlessly. But in time, its effectivity starts to fade...
-
Sep 2nd, 2020, 01:41 PM
#6
Re: Detect Windows 10 Shutdown Event
Given how quickly things change, there is only so much you can do to make your code future proof. But hey, the 16 year old code works, right?
-
Sep 3rd, 2020, 06:10 AM
#7
Thread Starter
Junior Member
Re: Detect Windows 10 Shutdown Event
Originally Posted by Peter Swinkels
Given how quickly things change, there is only so much you can do to make your code future proof. But hey, the 16 year old code works, right?
Hahaha some do. Believe me I've done several updates. This is minor but kinda annoying. It prevents Windows 10 from shutting down or restarting especially after an update. That's why I need a trigger to detect a shutdown process so I can end my application accordingly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|