Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top