|
-
Dec 28th, 2005, 01:52 PM
#1
Thread Starter
Member
[RESOLVED] catching and terminating shutdown command
Hello everyone,
I have an off the shelve application that has some irritating behavior. Everytime you close it, it will log you out of Windows. I spoke to the vendor today and they told me that is the way it is supposed to work.
Anyway, I am wondering if there is a way in vb.net to catch this shutdown command and terminate it. I basically want to have an application or service running in the background looking for shutdown commands.
Thanks
-
Dec 28th, 2005, 03:28 PM
#2
Re: catching and terminating shutdown command
I think you can try to detect the WM_QUERYENDSESSION message in your form, then cancel it...
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 29th, 2005, 09:58 AM
#3
Thread Starter
Member
Re: catching and terminating shutdown command
Hi Gigemboy,
Thanks for the code. Do I need to add a reference or anything to my project? I keep getting the error "Type Message is not defined."?
Thanks
-
Dec 29th, 2005, 10:16 AM
#4
Re: catching and terminating shutdown command
Also, running the command "shutdown -a" in the console aborts a shutdown. Not sure if that helps any but you could always have your program send that command or use it yourself if you get in a pinch.
Unsure about the posted API code though
-
Dec 29th, 2005, 12:32 PM
#5
Lively Member
Re: catching and terminating shutdown command
FrustratedFlash,
What version of vb are you runnig.
"A candle loses nothing by lighting another candle."
-
Dec 29th, 2005, 12:47 PM
#6
Thread Starter
Member
Re: catching and terminating shutdown command
Hi Safewithyou247 and everyone else.
I figured out my problem. I was trying to get this to work as a console application instead of a Windows application. I have it in a form now and it is working great.
Thank you all for your support.
-
Dec 29th, 2005, 03:27 PM
#7
Re: catching and terminating shutdown command
Good deal. If your thread is resolved, you can go to the top inder "thread tools" and mark the thread as "resolved"
-
Jun 2nd, 2007, 06:04 PM
#8
Addicted Member
Re: [RESOLVED] catching and terminating shutdown command
Does this work in VB 2005? If so, how do I call it?
Thanks
-
Jun 3rd, 2007, 04:56 AM
#9
Re: [RESOLVED] catching and terminating shutdown command
 Originally Posted by GedOfEarthsea
Does this work in VB 2005? If so, how do I call it?
Thanks
What is gigemboy's code but two member variables and a method. How would you normally use two member variables and a method in a WinForms app?
-
Jun 3rd, 2007, 11:53 AM
#10
Addicted Member
Re: [RESOLVED] catching and terminating shutdown command
You would do:
WndProc()
But what do I put in the parenthesis?
-
Jun 3rd, 2007, 05:29 PM
#11
Re: [RESOLVED] catching and terminating shutdown command
 Originally Posted by GedOfEarthsea
You would do:
WndProc()
But what do I put in the parenthesis?
WndProc is the method that processes messages from Windows. That's why it has an argument of type System.Windows.Forms.Message. The idea of overriding the WndProc method is to detect one or more specific messages from Windows and change the behaviour of the window by executing custom code when those messages are received. You don't call the WndProc method yourself. It gets executed every time the OS sends a message to the window.
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
|