anyone know how to intercept windows shutdown message and discard it b4 windows shuts down in other words prevent or delay windows shutdown?
Printable View
anyone know how to intercept windows shutdown message and discard it b4 windows shuts down in other words prevent or delay windows shutdown?
You cannot prevent this, because shutting down is related to the hardware of a computer.
Simple, it's really funny: Try this:
Create a new project, and in the Form1 code paste this:
No API crap at all... No all you have to do is make the form invisible or something like that....Code:Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = True
End Sub
That's all! :-)
Rob
that prevents a Form from closing, but does not prevent windows from shutting off.
I know what you mean Megatron, but it actually does work on my PC (Win2000Pro) and on a server (WinNT 4 sp6a).
Have you tried it? Have a go and see for yourself!
P.s. You may have to compile to .exe and run that... I've tried it, and it really works!
Rob
I just pushed the power button and turn my computer off... As I said earlier, the power is controlled by hardware, thus you can't prevent it.
Not always true! :D
When you have an ACPI power button (most modern pc's), Windows does control the shutdown! It's actually possible to hook the shutdown routine and prevent it from turning the pc off when you press the power button.
Most BIOS also have an option to turn the PC off when you jold POWER for 4 seconds, but that's also software and can be disabled.
You can always pull the plug of-course.
Gerco.
Eventually windows will say that the programs has stopped responding and it will ask you to close the program down, but also you can use InitiateSystemShutdown API call and use the EWX_FORCE flag to force windows to close all applications, so in the end, you will not be able to prevent windows from shuting down
Once you hold it for 5 seconds, the software doesn't have any control over it.Quote:
Originally posted by Gerco
Most BIOS also have an option to turn the PC off when you jold POWER for 4 seconds, but that's also software and can be disabled.
Untrue...
What is the thing that counts the 5 seconds? I have had situations in which my pc had crashed so badly that holding the power button for 10 seconds didn't do anything at all.
The software for the 5 second countdown is in the BIOS, but it's still software.
Gerco.
They cannot have everything supported by software. There has to be a way to shut down the computer without having to deal with software, because it's the software that does the crashing. They need a way for users to shut everything off, thus you cannot prevent a shut down.
I haven't heard of a machine that let's the software control the power after the 5 second deal.
Well in the BIOS you can choose to habe the power button switch the PC off instantly or after 4 seconds...
In theory, you can intercept the BIOS at the 4 second countdown point and abort it, unless that routine is in real ROM of-course...
But afaik, there is no program that allows you to do this. But I do have a 'power button override' option in my BIOS. And it doesn't matter if I hold down the Power button 5 seconds or a year, it won't shut down!
Gerco.
That's when you pull the plug :)
Maybe it's the newer machines that have this feature, because I purchased my PC in 2000 and it does not allow me to intercept after 5 seconds.
I guess, I bought a new Mainboard 6 months ago and it does...
I can set it to Instant off, 4 second delay or disabled (override)
Gerco.
BamBam, you may want to use the UnloadMode parameter to assure that it is Windows that is trying to unload your app and not the user closing the app normally (i.e. clicking the X button)....
(note: you have to compile this program to an exe file to test this code)
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim retval As Integer
If UnloadMode = vbAppWindows Then
retval = MsgBox("Do you want To shut down Windows?", vbYesNo)
If retval = vbNo Then
Cancel = True
End If
End If
End Sub
Won't windows say:
'This application is not responding to windows shutdown command, do you want to end now?'
I know WindowsNT does, but 98?
Gerco.
Yes.