Board index » Visual Studio » Stopping windows from shutting down

Stopping windows from shutting down

Visual Studio280
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


-
 

Re:Stopping windows from shutting down



"Richard M. Geis" <rmgeis@burnoutboss.com>wrote in message



Quote
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.





-

Re:Stopping windows from shutting down

"Jeff Johnson [MVP: VB]" <i.get@enough.spam>wrote in message

Quote
"Richard M. Geis" <rmgeis@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..."



-

Re:Stopping windows from shutting down



"Richard M. Geis" <rmgeis@burnoutboss.com>wrote in message

Quote
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





-

Re:Stopping windows from shutting down

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:

Quote
"Richard M. Geis" <rmgeis@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







-

Re:Stopping windows from shutting down

"Richard M. Geis" <rmgeis@burnoutboss.com>wrote in message

Quote
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..."



-

Re:Stopping windows from shutting down



"Richard M. Geis" <rmgeis@burnoutboss.com>wrote in message

Quote
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





-

Re:Stopping windows from shutting down

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:

Quote
"Richard M. Geis" <rmgeis@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.







-