|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Stopping windows from shutting downI 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 "Richard M. Geis" <rmg***@burnoutboss.com> wrote in message Look at the QueryUnload event of the Form object. Check out the UnloadMode 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. and the Cancel parameters. "Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message And realize that if the shutdown has been "forced" then you may not be ablenews: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. 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..." "Richard M. Geis" <rmg***@burnoutboss.com> wrote in message Clarification? Are you referring to stopping your application from closingnews: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 or stopping "Windows" OS from shutting down? Gerald 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 > > "Richard M. Geis" <rmg***@burnoutboss.com> wrote in message Cancel from Form_Unload won't stop a shutdown. Move your code tonews: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) Form_QueryUnload and try it. -- Reply to the group so all can participate VB.Net: "Fool me once..."
Show quote
Hide quote
"Richard M. Geis" <rmg***@burnoutboss.com> wrote in message You need to move that code to the QueryUnload event and check the UnloadMode 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 > 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 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. > > |
|||||||||||||||||||||||