-1

I made this little code to stop the closing of the application.

Public Sub New()
    InitializeComponent()
    AddHandler SystemEvents.SessionEnding, AddressOf SessionEndingEvtHandler
End Sub

Private Sub SessionEndingEvtHandler(sender As Object, e As SessionEndingEventArgs)
    MessageBox.Show("Cancelling Windows shutdown")
    e.Cancel = True
End Sub

It works fine, the application doesn't close anymore. But when I try to shutdown the system (Windows 8) a fullscreened prompt appears, with my application listed on it, and asking me to confirm the shutdown or cancel it.

My question is, how can I Cancel the shutdown ?

I tried to activate the cancel button (detail on this screen link) with :

SendKeys.Send("{ENTER}") 

But it doesn't work

Any idea how to simulate the cancel button action ?

Thanks, i apologise for my english, i'm french.

10
  • 11
    The days that this was still possible are long over. Jan 22, 2014 at 21:59
  • 3
    I think the important question here is why would you want to do such a thing?
    – Gabe
    Jan 23, 2014 at 2:10
  • 3
    If the user wants to shut down the system, the system will shut down. Full stop. (And even if your program could stop them, they will just pull the power cord out)
    – user253751
    Jan 23, 2014 at 5:28
  • 1
    The user can also run (e.g.) shutdown -f to force the shutdown.
    – Neil
    Jan 23, 2014 at 10:39
  • 1
    @user3225327 If the user shuts down the computer and then once again chooses to shut down the computer at the shut down confirmation screen, then it's a safe bet that they want to shut down their computer. The shut down confirmation screen is there to confirm the user's intentions, your app is not necessary and is only getting in the way. Why would a user need to shut down and then confirm it twice?
    – Roy
    Jan 23, 2014 at 13:36

1 Answer 1

11

If the user shouldn't be capable of shutting down the system, then the system administrator should remove their shutdown permission via group policy. I can see this being the case in certain business applications or a kiosk (although if the kiosk user can get to the shutdown button you're doing it wrong).

There is absolutely no reason for an app to completely stall the shutdown of a system - trust your user, if they are shutting down AND they click the option to force your app closed, then they are already aware that they are shutting down your app and it is clear that they want it shut down. What you have now will already stop them from shutting down without realizing that they're stopping your app from doing whatever it needs to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.