Results 1 to 7 of 7

Thread: Detect Windows 10 Shutdown Event

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    27

    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!

  2. #2

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    27

    Resolved Re: Detect Windows 10 Shutdown Event

    Thanks for your reply. However, that thread was 7 years old and not done on a 64bit Windows 10 system. That's the code that I am currently using too and it doesn't trigger anymore

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Detect Windows 10 Shutdown Event

    You’re welcome. Yes, it is old. Perhaps it could be updated?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    27

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

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    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?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    27

    Re: Detect Windows 10 Shutdown Event

    Quote Originally Posted by Peter Swinkels View Post
    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
  •  



Click Here to Expand Forum to Full Width