469,579 Members | 1,899 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Canceling and continuing shutdown/reboot/logoff


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
0 1655

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jet | last post: by
6 posts views Thread by Mr Newbie | last post: by
reply views Thread by Allan Bredahl | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.