|
-
Dec 29th, 2005, 05:29 PM
#1
Prevent Windows Shutdown
Here is a little code snippet that prevents the windows from shutting down if your app is running, it intercepts the WM_QUERYENDSESSION message that is sent to the open windows on a system shutdown, and cancels the message.
VB Code:
'constants needed, form level
Private Const WM_QUERYENDSESSION As System.Int32 = &H11
Private Const WM_CANCELMODE As System.Int32 = &H1F
'the sub to intercept the windows messages
Protected Overrides Sub WndProc(ByRef ex As Message)
If ex.Msg = WM_QUERYENDSESSION Then
'cancel the message
Dim MyMsg As New Message
MyMsg.Msg = WM_CANCELMODE
MyBase.WndProc(MyMsg)
Else
'send the message as normal
MyBase.WndProc(ex)
End If
End Sub
-
Dec 30th, 2005, 12:06 PM
#2
Re: Prevent Windows Shutdown
you can actually CANCEL the shutdown!? no wonder windows security is full of holes :/ sounds like a nice vulnerability for viruses to me, i mean reading that a shutdown is about to happen is useful so you can make your program stop, but cancelling it.. eek..
Although i guess there is always the power button 
nice post!
-
Dec 31st, 2005, 05:12 PM
#3
Re: Prevent Windows Shutdown
lol well there was a seemingly valid reason for it, in this post: http://www.vbforums.com/showthread.php?t=378604
-
Apr 15th, 2008, 06:49 AM
#4
Frenzied Member
Re: Prevent Windows Shutdown
I put that code on my program to test it, then when i ran my program i clicked shutdown and that code didnt cancel it.
-
Apr 15th, 2008, 06:51 AM
#5
Frenzied Member
Re: Prevent Windows Shutdown
Oh i see i made a error when i tryied out ur code.
-
Apr 15th, 2008, 10:15 AM
#6
Re: Prevent Windows Shutdown
Has anyone tested this in Vista? The last thing I read from MS is that programs like this Don't prevent Vista from shutting down. Vista will give it an allotment of 30 seconds to finish up and then it's terminated regardless. I'm curious if Vista actually does that or not.
-
Apr 15th, 2008, 06:47 PM
#7
Re: Prevent Windows Shutdown
 Originally Posted by JuggaloBrotha
Has anyone tested this in Vista? The last thing I read from MS is that programs like this Don't prevent Vista from shutting down. Vista will give it an allotment of 30 seconds to finish up and then it's terminated regardless. I'm curious if Vista actually does that or not.
I've tried it, this is what appears:
-
Apr 15th, 2008, 08:12 PM
#8
Re: Prevent Windows Shutdown
It's good to know that MS has included the ability to at least notify you when a program is preventing shut down/ log off
-
Dec 3rd, 2008, 08:37 AM
#9
New Member
Re: Prevent Windows Shutdown
Does anyone know how to check which window or process sent the "WM_QUERYENDSESSION" message?
I'm trying to determine which process is shutting certain PCs down.
I tried "ex.HWnd", but that returned the current window.
Thanks in advance!
-
Dec 3rd, 2008, 05:37 PM
#10
Frenzied Member
Re: Prevent Windows Shutdown
 Originally Posted by scotsmanscott
Does anyone know how to check which window or process sent the "WM_QUERYENDSESSION" message?
I'm trying to determine which process is shutting certain PCs down.
I tried "ex.HWnd", but that returned the current window.
Thanks in advance!
You should place that question in the VB.NET forum as a new thread, this is the codebank. You will get more anwsers faster if you do a new thread in the right section.
P.S. Welcome to the forums!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|