Visual basic capture shut down event

Posted on 2006-04-14
Last Modified: 2010-04-17
if Windows is shutting down (because the user press START->TURN OFF COMPUTER->SHUTDOWN), can visual basic trap this event ?
If so, how to program it to capture that event.
Thanks a lot!!! :)
Question by:clemseed
    LVL 8

    Accepted Solution

    I don't know if this is enough for you, but you can use:

    Private Sub Form_Unload(Cancel As Integer)

    End Sub

    That will load at shutdown, however it wont tell you if it was caused by exit or shutdown.
    LVL 8

    Expert Comment

    Or also you can do:

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        'UnloadMode possibilities:
        '0   The user has chosen the Close command from the Control-menu box on the form.
        '1   The Unload method has been invoked from code.
        '2   The current Windows-environment session is ending.
        '3   The Microsoft Windows Task Manager is closing the application.
        '4   An MDI child form is closing because the MDI form is closing.
    End Sub

    Where shutdown will trigger this with an UnloadMode of 2

    Expert Comment


    It appears your question is answered here (Quote:  "...little code snippet that prevents the windows from shutting down if your app is running..."):


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Add mobile access to browser application 3 108
    sameEnds challenge 25 57
    fix34  challenge 9 70
    mapAB Challlenge 35 54
    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now