Important alert: (current site time 7/15/2013 9:15:01 AM EDT)
 

VB icon

Stop a Shutdown

Email
Submitted on: 4/10/2004 5:37:38 PM
By: Dan Dayon 
Level: Beginner
User Rating: By 6 Users
Compatibility: VB.NET
Views: 22272
(About the author)
 
     This stops the system from shutting down when windows goes to shut down...
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Stop a Shutdown
// Description:This stops the system from shutting down when windows goes to shut down...
// By: Dan Dayon
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2275&lngWId=10//for details.//**************************************

'Constants
Private Const WM_QUERYENDSESSION As System.Int32 = &H11
Private Const WM_CANCELMODE As System.Int32 = &H1F
'And the Sub itself....
Protected Overrides Sub WndProc(ByRef m As Message)
	If m.Msg = WM_QUERYENDSESSION Then
'Check the m, if it's trying to shut down, don't send it. Send a new message cancelling it.
		Dim x As New Message
		x.Msg = WM_CANCELMODE
		MyBase.WndProc(x)
	Else
'Otherwise, just send the message.
		MyBase.WndProc(m)
	End If
End Sub


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/11/2004 10:30:27 AMDan Dayon

Enjoy. I didn't see any other examples of this here.
(If this comment was disrespectful, please report it.)

 
4/12/2004 11:20:26 AMYuri Vishnevsky

wow! this works great :-) thanks
(If this comment was disrespectful, please report it.)

 
4/12/2004 2:47:04 PMZorrer

good for sharing
(If this comment was disrespectful, please report it.)

 
4/13/2004 3:34:54 PMYuri Vishnevsky

is there a way to make windows think your application has exited when it hasn't using m.msg?
(If this comment was disrespectful, please report it.)

 
10/17/2005 1:16:45 AMtiny t.

i spent so much time looking for this simple code in the internet & msdn. finally i've found it. thanks a lot.
(If this comment was disrespectful, please report it.)

 
10/28/2005 1:51:10 PMDominator Legend

Hallow, where can i write the wndproc, when i past this code and run nothing happen, cause wndproc dosn't called, is there is somthing i miss???, please help.

(If this comment was disrespectful, please report it.)

 
1/24/2006 7:39:30 AMVijeyAshok

huh there is another simpler way to do the same , without any api's let me post it


(If this comment was disrespectful, please report it.)

 
8/10/2006 2:42:43 PMsri

please suggest me how to shut down the PC using VB.Net ..please send the sub code for it...and mail me at d_srinivas84@yahoo.com
(If this comment was disrespectful, please report it.)

 
11/2/2006 8:04:53 PMThief_

I want to use this code to execute a procedure called TestRun which runs an external application when the user logs off. How do I add this to the above code?

From my experiments, you can not call TestRun from within the WndProc else the OS will kill it anyway.

The only thing I can think of is:

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
'MessageBox.Show("activated")
If SystemShutdown Then
SystemShutdown = False
Call TestRun()
End If
End Sub

where SystemShutdown is a boolean which is set after the "x.Msg = WM_CANCELMODE" line. But is this the CORRECT way to do it?
(If this comment was disrespectful, please report it.)

 
10/26/2007 3:46:46 PMjm

Do I need to reference anything in particular to make this work? I am using VB6 and it doesn't work, it just give me syntax errors on the const's and protected override statement. Thanks
(If this comment was disrespectful, please report it.)

 
9/13/2008 7:06:57 AMvijay gatam

it was fantastic .

plz make such a cool code.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.