2 Replies - 2752 Views - Last Post: 24 June 2011 - 08:43 AM

#1 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Detecting and Aborting Windows Shutdown from VB

Posted 12 March 2005 - 09:46 PM

Description: Detect and Abort Windows Shutdown using VB.
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
      If UnloadMode = vbAppWindows Then
' If Windows is trying to shut-down
         tmp = MsgBox("Do you want to Shutdown?", vbYesNoCancel, "Confirm Shutdown")
' If No...then abort Shutdown by Inverting Close Mode         
         If tmp = vbNo Then Cancel = Not Cancel
      End If
End Sub

Is This A Good Question/Topic? 0
  • +

Replies To: Detecting and Aborting Windows Shutdown from VB

#2 10e12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-May 09

Re: Detecting and Aborting Windows Shutdown from VB

Posted 25 May 2009 - 12:11 PM

Correction, if your application is closing down, not Windows (but The Window). If you have a solution to hooking the Win O/S to prevent accidental/forced close of your own app, I would love it. I need a block to prevent users from shutting down forcefully before I can save last settings and possibly lose order data.
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes   User is offline

  • Product Manager
  • member icon

Reputation: 603
  • View blog
  • Posts: 3,085
  • Joined: 19-May 09

Re: Detecting and Aborting Windows Shutdown from VB

Posted 24 June 2011 - 08:43 AM

More concisely, Cancel = MsgBox("Do you want to Shutdown?", vbYesNoCancel, "Confirm Shutdown") = vbNo can remove a line of code and a variable. Not saying this is the way to do it, of course; every style needs to take both conciseness and clarity into account.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1