473,408 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

VB.NET App Prevents logoff/shutdown ?

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 ?
Nov 21 '05 #1
6 11240
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
-------------------
"Jm" <ja*****@ihug.com.au> wrote in message
news:ct**********@lust.ihug.co.nz...
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 ?

Nov 21 '05 #2
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
-------------------
"Jm" <ja*****@ihug.com.au> wrote in message
news:ct**********@lust.ihug.co.nz...
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 ?

Nov 21 '05 #3
You need to override 'wndproc'

Declaration:

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

#Region "Window Proc (SUB)"
<System.Security.Permissions.PermissionSetAttribut e(System.Security.Permissions.SecurityAction.Deman d, 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

"Ken Tucker [MVP]" wrote:
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
-------------------
"Jm" <ja*****@ihug.com.au> wrote in message
news:ct**********@lust.ihug.co.nz...
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 ?

Nov 21 '05 #4
You need to override 'wndproc'

Declaration:

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

#Region "Window Proc (SUB)"
<System.Security.Permissions.PermissionSetAttribut e(System.Security.Permissions.SecurityAction.Deman d, 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

"Ken Tucker [MVP]" wrote:
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
-------------------
"Jm" <ja*****@ihug.com.au> wrote in message
news:ct**********@lust.ihug.co.nz...
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 ?

Nov 21 '05 #5
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" <Cr**********@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
You need to override 'wndproc'

Declaration:

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

#Region "Window Proc (SUB)"
<System.Security.Permissions.PermissionSetAttribut e(System.Security.Permissi
ons.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

"Ken Tucker [MVP]" wrote:
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
-------------------
"Jm" <ja*****@ihug.com.au> wrote in message
news:ct**********@lust.ihug.co.nz...
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 ?

Nov 21 '05 #6
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_...fshutdown-.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Jan 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think...
7
by: JonBoy | last post by:
Is it possible to put the logoff/shutdown/restart buttons on an ASP page or something similar? If so can anyone point me in the direction of some code please or where I can read how to do it ...
0
by: Allan Bredahl | last post by:
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 :...
4
by: sanket gupta | last post by:
Hi guys , I face a peculiar problem. I have a mutithreaded software trhat uses sockets to connect to my webserver. The problem is that while my software is running , windows is unable to...
0
by: Jm | last post by:
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...
8
by: Jm | last post by:
Hi All I have an app that when running if a user selects logoff or shutdown from the start menu, it will close itself but not logoff windows or shutdown. From what i have found so far its most...
2
by: mikemiller.innova | last post by:
I developed a C# Windows App that requires a user to input their real name and what they did to the server while they were online. I am going to launch the app att shutdown via a logoff script. ...
1
by: CyberSoftHari | last post by:
I want to get applications running (Showing) in Task bar (and show those applications running) and Cancel windows LogOff, Shutdown, Restart when user try to Click windows LogOff, Shutdown, Restart
1
by: Clemente | last post by:
Hi, We have a VB.Net application that is sleeping until it receives a logoff/shutdown event. We want the application running on Vista and XP. When the application receives those events it has...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.