Remote reboot command - STOP

Posted on 2006-04-06
Last Modified: 2010-04-07
Corporate network.  They use programs to push updates to our desktops (Mirimba? or something)
Some updates need a reboot.

Any way I can stop the remote command to reboot?  Registry change?  Windows API?  These "updates" usually occur at night when I am absent.

I have critical scripts running and need to stop the reboot.  I.T. has not been helpful in this situation.

Thanks.  (Where does a question of this type belong?)  I have a background in VB so I asked it here.

Need a long term answer.  If the solution is something I need to do daily, then some type of script I can write and run with the task scheduler.
Question by:mayfieldjr
    LVL 13

    Expert Comment


    have you ever been at your computer when it reboots,

    if yes, does it display some screen like rebooting in 30 seconds?

    then try this:

    type in dos (or the runbox) "shutdown -a" (without quotes)

    if it stops your pc, try creating a program that looks for the shutdown window, and than executes the shutdown -a command
    LVL 29

    Expert Comment

    Yes this is possible to do in VB, What you need to do is setup a callback and wait for WM_QUERYENDSESSION message. This message is sent to all applications before the system is about to shutdown. This gives your applications a chance to either allow the shutdown or bypass the shutdown. What you must do is return False for the WindowProc in order to not allow the system to shutdown.

    LVL 29

    Expert Comment

    Note: Just be aware that the above might not be full proof depending on how the update application is shutting down the computer.

    Author Comment

    I am not familiar with setting up callbacks.  Caould I get an example please?

    I am guessing I can just create a standard EXE with a blank form that is somehow always checking for the WM_QUERYENDSESSION message.  When I get it the I have the program return 0??

    LVL 29

    Accepted Solution

    You could try the below example I whiped up it should work...

    'Create new standard exe project
    'Add 1 listbox to form
    'Add 1 Module.bas

    ' Compile the application, then run the application and try to shutdown windows. It should abort the shutdown.

    '---- Module1.bas ----

    Option Explicit

        Private Declare Function SetWindowLongA Lib "user32" ( _
            ByVal hwnd As Long, ByVal nIndex As Long, _
            ByVal dwNewLong As Long) As Long
        Private Declare Function CallWindowProcA Lib "user32" ( _
            ByVal lpPrevWndFunc As Long, _
            ByVal hwnd As Long, ByVal Msg As Long, _
            ByVal wParam As Long, ByVal lParam As Long) As Long
        Private Const GWL_WNDPROC = (-4)
        Private Const WM_QUERYENDSESSION = &H11
        Private Const WM_ENDSESSION = &H16
        Dim ProcRet As Long
    Public Sub BeginDetectingShutdown(ByVal hwnd As Long)
        ProcRet = SetWindowLongA(hwnd, GWL_WNDPROC, AddressOf CatchShutdown)
    End Sub

    Public Sub StopDetectingShutdown(ByVal hwnd As Long)
        Call SetWindowLongA(hwnd, GWL_WNDPROC, ProcRet)
    End Sub

    Public Function CatchShutdown( _
        ByVal hwnd As Long, _
        ByVal uMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
       Select Case uMsg
                CatchShutdown = Abs(False)
                    Form1.List1.AddItem "Windows attemted to shutdown " & Time
            Case WM_ENDSESSION
                CatchShutdown = Abs(False)
            Case Else
            CatchShutdown = CallWindowProcA(ProcRet, hwnd, uMsg, wParam, lParam)
       End Select
    End Function

    '--- Form1 ---

    Option Explicit

    Private Sub Form_Load()
        BeginDetectingShutdown Me.hwnd
    End Sub

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        StopDetectingShutdown Me.hwnd
    End Sub

    Author Comment

    Perfect.  Wonderful.  Worked like a charm.  Excellent!!!

    Thank you.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    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

    19 Experts available now in Live!

    Get 1:1 Help Now