Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Remote reboot command - STOP

Posted on 2006-04-06
Medium Priority
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
  • 3
  • 2
LVL 13

Expert Comment

ID: 16398124

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

ID: 16399130
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

ID: 16399156
Note: Just be aware that the above might not be full proof depending on how the update application is shutting down the computer.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 16401827
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

nffvrxqgrcfqvvc earned 1000 total points
ID: 16404383
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

ID: 16411879
Perfect.  Wonderful.  Worked like a charm.  Excellent!!!

Thank you.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

572 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