Results 1 to 2 of 2

Thread: having your program run at shutdown

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    34

    Exclamation

    I have a program that I need to run at shutdown (after you click shutdown or restart from the menu). Does anybody know the code to do this and when I would have to load the program up in the first place (run the program at Startup and then it know when the computer is shutting down. Also I guess I need to know how to stop the computer from fully shutting down until my program is done and one it is done, how to let the computer continue shutting down! Phew!

    thanks for everything!

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    If your app has a form in it you can use the following to run some code or cancel the windows shutdown....

    Code:
    Option Explicit
    
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        ' This unload mode is only passed to QueryUnload event when windows is _
            trying to shut down and your app is running
        If UnloadMode = vbAppWindows Then
            Dim iResponse As Integer
            
            ' run your code here
    
            iResponse = MsgBox("Continue shutting down Windows?", vbYesNo)
            
            If iResponse = vbNo Then
                
                ' if user decides not to shut down windows, then cancel the unload of this _
                  form thus cancelling Windows from shutting down
                Cancel = True
                
            End If
            
        End If
        
    End Sub
    Note: To test this code you will have to compile the project into an .exe file and have it running when you choose to shutdown windows. Hope this helps!
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width