PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Prevent Windows Shutdown-VBForums
Results 1 to 10 of 10

Thread: Prevent Windows Shutdown

  1. #1

    Thread Starter
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Prevent Windows Shutdown

    Here is a little code snippet that prevents the windows from shutting down if your app is running, it intercepts the WM_QUERYENDSESSION message that is sent to the open windows on a system shutdown, and cancels the message.
    VB Code:
    1. 'constants needed, form level
    2.     Private Const WM_QUERYENDSESSION As System.Int32 = &H11
    3.     Private Const WM_CANCELMODE As System.Int32 = &H1F
    4.  
    5.     'the sub to intercept the windows messages
    6.     Protected Overrides Sub WndProc(ByRef ex As Message)
    7.         If ex.Msg = WM_QUERYENDSESSION Then
    8.             'cancel the message
    9.             Dim MyMsg As New Message
    10.             MyMsg.Msg = WM_CANCELMODE
    11.             MyBase.WndProc(MyMsg)
    12.         Else
    13.             'send the message as normal
    14.             MyBase.WndProc(ex)
    15.         End If
    16.     End Sub

  2. #2
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: Prevent Windows Shutdown

    you can actually CANCEL the shutdown!? no wonder windows security is full of holes :/ sounds like a nice vulnerability for viruses to me, i mean reading that a shutdown is about to happen is useful so you can make your program stop, but cancelling it.. eek..

    Although i guess there is always the power button

    nice post!

  3. #3

    Thread Starter
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: Prevent Windows Shutdown

    lol well there was a seemingly valid reason for it, in this post: http://www.vbforums.com/showthread.php?t=378604

  4. #4
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Prevent Windows Shutdown

    I put that code on my program to test it, then when i ran my program i clicked shutdown and that code didnt cancel it.

  5. #5
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Prevent Windows Shutdown

    Oh i see i made a error when i tryied out ur code.

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,283

    Re: Prevent Windows Shutdown

    Has anyone tested this in Vista? The last thing I read from MS is that programs like this Don't prevent Vista from shutting down. Vista will give it an allotment of 30 seconds to finish up and then it's terminated regardless. I'm curious if Vista actually does that or not.

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: Prevent Windows Shutdown

    Quote Originally Posted by JuggaloBrotha
    Has anyone tested this in Vista? The last thing I read from MS is that programs like this Don't prevent Vista from shutting down. Vista will give it an allotment of 30 seconds to finish up and then it's terminated regardless. I'm curious if Vista actually does that or not.
    I've tried it, this is what appears:
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,283

    Re: Prevent Windows Shutdown

    It's good to know that MS has included the ability to at least notify you when a program is preventing shut down/ log off

  9. #9
    New Member
    Join Date
    Dec 2008
    Posts
    1

    Re: Prevent Windows Shutdown

    Does anyone know how to check which window or process sent the "WM_QUERYENDSESSION" message?

    I'm trying to determine which process is shutting certain PCs down.

    I tried "ex.HWnd", but that returned the current window.

    Thanks in advance!

  10. #10
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Prevent Windows Shutdown

    Quote Originally Posted by scotsmanscott
    Does anyone know how to check which window or process sent the "WM_QUERYENDSESSION" message?

    I'm trying to determine which process is shutting certain PCs down.

    I tried "ex.HWnd", but that returned the current window.

    Thanks in advance!
    You should place that question in the VB.NET forum as a new thread, this is the codebank. You will get more anwsers faster if you do a new thread in the right section.

    P.S. Welcome to the forums!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width