Prevent user from closing an application but let the system close it
Posted on 2006-05-26
I'm developing an application in vb.net thet needs to register computer usage time.
I must prevent user from closing the application and for that i used
Private Sub frm_Principal_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If not canClose Then
Me.WindowState = FormWindowState.Minimized
e.Cancel = True
canclose is a boolean tha i use to force application closing when true.
The problem is that when the user tries to log off or shut down the pc, windows tries to close the application. , the system stops the shutting down or logging of process because canClose is set to false.
I used the microsoft.Win32.SystemEvents.SessionEnding event to switch canClose to True, but frm_Principal_Closing happens first so the SessionEnding event never fire.