472,143 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

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 1759

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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.