By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Canceling and continuing shutdown/reboot/logoff

P: n/a

Hi All
I am trying to construct an application that is able to cancel a machine
shutdown, reboot or logoff. And after performing some stuff to perform the
original shutdown order : Shutdown/reboot/logoff.

I have tried this :

AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf
ShutDown.OnShuttingdown

Public Shared Sub OnShuttingdown(ByVal sender As Object, ByVal e As
Microsoft.Win32.SessionEndingEventArgs)
e.Cancel = True
End Sub

But this doesn't seem to work since the canceling of the system shutdown
does not cancel the application shutdown and therefore it gives no meaning
THe only way I can prevent the app closing down is by showing a messagebox i
my OnShuttingDown handler. But if I do not close the messagebox within an
couple of seconds the system tries to close this and then continues the
shutdown regardless that the cancel = true have been set.

Then I tried this which work better, but my problem here is, that I do not
know if I'm handling a shutdown, reboot or logoff:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
ShutDown.systemShutdown = True
End If

MyBase.WndProc(m)
End Sub

Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If (ShutDown.systemShutdown) Then
ShutDown.systemShutdown = False
e.Cancel = True
Else
e.Cancel = False
Application.Exit()
End If
End Sub
Does anyone know how to do this, so I'm able to stop and continue any type
of 'shutdown'
Thanks in advance

Allan Bredahl

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.