VB.NET App Prevents logoff/shutdown ?

J

Jm

Hi All

I have a simple vb.net app that once run for some reason does not allow me
to log off or shutdown the pc ? When i try to do so it will close my app and
then will only shutdown or logoff if i attempt to do so once again ? Does
anybody have any does why this would be so ?
 
K

Ken Tucker [MVP]

Hi,

The forms closing event allows you to cancel the form from closing.
If you cancel a form from closing it would prevent windows from shutting
down or logging off.

Ken
-------------------
Hi All

I have a simple vb.net app that once run for some reason does not allow me
to log off or shutdown the pc ? When i try to do so it will close my app and
then will only shutdown or logoff if i attempt to do so once again ? Does
anybody have any does why this would be so ?
 
G

Guest

You need to override 'wndproc'

Declaration:

' Exit Windows message
Private Shared WM_QUERYENDSESSION As Integer = &H11

#Region "Window Proc (SUB)"


<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
' Listen for operating system messages
If m.Msg = WM_QUERYENDSESSION Then
' Close the application
Application.Exit()
End If
' Handle the message
MyBase.WndProc(m)
End Sub

I hope this helps
 
J

Jm

Hi Crouchie

Thanks for the reply, I attempted to use the code you provided inside the
form in question but it doesnt seem to change anything :-( I attempt to
logoff and my app closes but system still doesnt log off. Should i be
placing the code somewhere else ?

Thanks

Crouchie1998 said:
You need to override 'wndproc'

Declaration:

' Exit Windows message
Private Shared WM_QUERYENDSESSION As Integer = &H11

#Region "Window Proc (SUB)"
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissi
ons.SecurityAction.Demand, Name:="FullTrust")> _
 
Joined
Jan 19, 2006
Messages
1
Reaction score
0
VB.NET App Prevents shutdown/logoff

I had the same issue. I loaded a form from a module using the form.showdialog method (as I wanted the code in the module to stop running until the form was unloaded). Doing this prevents the machine it is running on from shuting down/logging off even if the app it'self closes using any method I have found on the web.

The only way I found round it is to show the form using .show and looping under that with a doevents as shown below. Not really nice but it's the only way I found this to work.


fPrograms.Show()
While fPrograms.Visible
Application.DoEvents()
System.Threading.Thread.Sleep(100)
EndWhile


I hope this helps.


 
I

Ic0n

I had the same issue. I loaded a form from a module using the form.showdialog method (as I wanted the code in the module to stop running until the form was unloaded). Doing this prevents the machine it is running on from shuting down/logging off even if the app it'self closes using any method I have found on the web.

The only way I found round it is to show the form using .show and looping under that with a doevents as shown below. Not really nice but it's the only way I found this to work.


fPrograms.Show()
While fPrograms.Visible
Application.DoEvents()
System.Threading.Thread.Sleep(100)
EndWhile


I hope this helps.


From http://developmentnow.com/g/38_2005_1_0_0_48238/VB-NET-App-Prevents-logoffshutdown-.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top