Home All Groups Group Topic Archive Search About

Stopping windows from shutting down

Author
1 Jun 2005 5:51 PM
Richard M. Geis
I need to stop windows from shutting down, but only if <condition> is
true. This is probably an easy thing to do, I looked in help for 30
minutes but couldn't find it.

Thanks in Advance

Author
1 Jun 2005 6:06 PM
Jeff Johnson [MVP: VB]
"Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
news:xKCdnRLTYM8-aADfRVn-tw@cablespeedmd.com...

>I need to stop windows from shutting down, but only if <condition> is true.
>This is probably an easy thing to do, I looked in help for 30 minutes but
>couldn't find it.

Look at the QueryUnload event of the Form object. Check out the UnloadMode
and the Cancel parameters.
Author
1 Jun 2005 6:47 PM
Bob Butler
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:uA12xStZFHA.3648@TK2MSFTNGP14.phx.gbl
> "Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
> news:xKCdnRLTYM8-aADfRVn-tw@cablespeedmd.com...
>
>> I need to stop windows from shutting down, but only if <condition> is
true.
>> This is probably an easy thing to do, I looked in help for 30
>> minutes but couldn't find it.
>
> Look at the QueryUnload event of the Form object. Check out the
> UnloadMode and the Cancel parameters.

And realize that if the shutdown has been "forced" then you may not be able
to stop it (and AFAIK you can't detect that except maybe by responding to
the Form_Unload event)

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
1 Jun 2005 7:53 PM
Gerald Hernandez
"Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
news:xKCdnRLTYM8-aADfRVn-tw@cablespeedmd.com...
> I need to stop windows from shutting down, but only if <condition> is
> true. This is probably an easy thing to do, I looked in help for 30
> minutes but couldn't find it.
>
> Thanks in Advance

Clarification? Are you referring to stopping your application from closing
or stopping "Windows" OS from shutting down?

Gerald
Author
2 Jun 2005 12:16 AM
Richard M. Geis
What I would like is a message box to come up like one does if you try
to shut down windows without saving text in notepad. Of course, one of
the options would stop windows from shuting down (or cancel shut down).

I have the following code in the form (unload) event but it has no
effect on windows shuying down:

Private Sub Form_Unload(Cancel As Integer)
j = 0
For i = 0 To furninst - 1
     If furnon(i) = True Or furnwait(i) > 0 Then j = j + 1
     If furndone(i) = True Then j = j - 1
Next i
If j > 0 Then
     If MsgBox("Furnace is currently running, close anyway?", vbYesNo,
"Warning") = vbNo Then
         Cancel = 1
     End If
End If
End Sub

Thanks

Gerald Hernandez wrote:
Show quoteHide quote
> "Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
> news:xKCdnRLTYM8-aADfRVn-tw@cablespeedmd.com...
>
>>I need to stop windows from shutting down, but only if <condition> is
>>true. This is probably an easy thing to do, I looked in help for 30
>>minutes but couldn't find it.
>>
>>Thanks in Advance
>
>
> Clarification? Are you referring to stopping your application from closing
> or stopping "Windows" OS from shutting down?
>
> Gerald
>
>
Author
2 Jun 2005 12:46 AM
Bob Butler
"Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
news:i6OdndK3judi0gPfRVn-qg@cablespeedmd.com
> What I would like is a message box to come up like one does if you try
> to shut down windows without saving text in notepad. Of course, one of
> the options would stop windows from shuting down (or cancel shut
> down).
>
> I have the following code in the form (unload) event but it has no
> effect on windows shuying down:
>
> Private Sub Form_Unload(Cancel As Integer)

Cancel from Form_Unload won't stop a shutdown.  Move your code to
Form_QueryUnload and try it.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
2 Jun 2005 12:53 AM
MikeD
Show quote Hide quote
"Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
news:i6OdndK3judi0gPfRVn-qg@cablespeedmd.com...
> What I would like is a message box to come up like one does if you try to
> shut down windows without saving text in notepad. Of course, one of the
> options would stop windows from shuting down (or cancel shut down).
>
> I have the following code in the form (unload) event but it has no effect
> on windows shuying down:
>
> Private Sub Form_Unload(Cancel As Integer)
> j = 0
> For i = 0 To furninst - 1
>     If furnon(i) = True Or furnwait(i) > 0 Then j = j + 1
>     If furndone(i) = True Then j = j - 1
> Next i
> If j > 0 Then
>     If MsgBox("Furnace is currently running, close anyway?", vbYesNo,
> "Warning") = vbNo Then
>         Cancel = 1
>     End If
> End If
> End Sub
>


You need to move that code to the QueryUnload event and check the UnloadMode
argument to see if Windows is shutting down.

Personally, I would advise against any such prompt unless it would be
detrimental to have Windows close at that particular time.  Normally, you
shouldn't interfere with Windows shutting down.  If a shutdown would be
detrimental, you should just do whatever you need to properly clean up and
then let Windows continue to shut down.

I can think of no good reason a program should interrupt a shut down except
to prompt to save data which has not been saved. Even security programs like
virus checkers and firewalls don't normally interrupt a shutdown of Windows.


--
Mike
Microsoft MVP Visual Basic
Author
2 Jun 2005 1:37 AM
Richard M. Geis
Thanks for the replies. That did stop windows from shutting down. I
needed to do this because this application runs a furnace through a com
port. I once accidentally shut down windows in the middle of running a
furnace and it took two hours to get back to where I was.

Another interesting note: this dosen't work when running inside of VB,
it has to be compiled and run from the .exe

Thnaks again, and sorry you had to tell me twice.

MikeD wrote:
Show quoteHide quote
> "Richard M. Geis" <rmg***@burnoutboss.com> wrote in message
> news:i6OdndK3judi0gPfRVn-qg@cablespeedmd.com...
>
>>What I would like is a message box to come up like one does if you try to
>>shut down windows without saving text in notepad. Of course, one of the
>>options would stop windows from shuting down (or cancel shut down).
>>
>>I have the following code in the form (unload) event but it has no effect
>>on windows shuying down:
>>
>>Private Sub Form_Unload(Cancel As Integer)
>>j = 0
>>For i = 0 To furninst - 1
>>    If furnon(i) = True Or furnwait(i) > 0 Then j = j + 1
>>    If furndone(i) = True Then j = j - 1
>>Next i
>>If j > 0 Then
>>    If MsgBox("Furnace is currently running, close anyway?", vbYesNo,
>>"Warning") = vbNo Then
>>        Cancel = 1
>>    End If
>>End If
>>End Sub
>>
>
>
>
> You need to move that code to the QueryUnload event and check the UnloadMode
> argument to see if Windows is shutting down.
>
> Personally, I would advise against any such prompt unless it would be
> detrimental to have Windows close at that particular time.  Normally, you
> shouldn't interfere with Windows shutting down.  If a shutdown would be
> detrimental, you should just do whatever you need to properly clean up and
> then let Windows continue to shut down.
>
> I can think of no good reason a program should interrupt a shut down except
> to prompt to save data which has not been saved. Even security programs like
> virus checkers and firewalls don't normally interrupt a shutdown of Windows.
>
>