Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How do I disable system shutdown?

Posted on 1999-07-16
Medium Priority
Last Modified: 2008-02-26
I need to disable the system shutdown.  I need to use something that disables that directly without a registry setting.  And also the code to disable the desktop will not work in this case.  Is there a way to use the API to do this?
Question by:sharmon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3

Expert Comment

ID: 1525250
Use the ExitWIndowsEx API..

Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long,
       ByVal dwReserved As Long) As Boolean
       Public Const EWX_FORCE = 4
       Public Const EWX_LOGOFF = 0
       Public Const EWX_REBOOT = 2
       Public Const EWX_SHUTDOWN = 1

Used something like this:

Dim res As Boolean
res = ExitWindowsEx (EWX_REBOOT, 0)


Expert Comment

ID: 1525251
Not any good to have multiple Netscape's open I guess, this was a comment for another question :)

What about having a VB program running and setting Cancel = True in the QueryUnload event of the main form? Does that work?


Author Comment

ID: 1525252
I was kinda wondering what you were thinking when I ready your first comment...:)  Nope, setting cancel will not help.  I am unsure if there is even a way to do this, if so I would have thought I would find it somewhere, but I can't.  No mention on MSDN or in any of my API books or on any VB site I have visited, but maybe someone knows a way.  Thanks....take care.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Expert Comment

ID: 1525253
Consider this....I did it once.  I made a program that TOTALLY COPIED the desktop.  The user would not know the difference between the program, full screen of course, and the real thing.  Then you could disable the desktop, disable this, that.....i'll look for my code.

Expert Comment

ID: 1525254
Just Ideas..

Perhaps something similar to having Outlook running seems to foil the shutdown on my NT box pretty effectively.  

Expert Comment

ID: 1525255
I would be interested to learn the requirement for disabling shutdown - seems awful extreme.  Shouldn't handling of the QueryUnload event in your main window form be enough as was suggested above?

Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)

 if AmIDone() Then  ' your own function. Or use a global flag
     cancel = False  ' ready to go bye bye
     cancel = True   ' not ready to quit
 end if

End Sub
LVL 10

Accepted Solution

viktornet earned 280 total points
ID: 1525256
The easiest way is to use cancel = False.... I dunno why it doesn't work for you... anyway, here is some code that Ijust got together... let's hope that this would help ;-))

Just try to increase the points a lil' if you know what I mean ;))

Option Explicit

Public Const GWL_WNDPROC = (-4)

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public TheProc As Long

Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        WindowProc = 0
        WindowProc = CallWindowProc(TheProc, hwnd, uMsg, wParam, lParam)
    End If
End Function

Option Explicit

Private Sub Form_Load()
    TheProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call SetWindowLong(hwnd, GWL_WNDPROC, TheProc)
End Sub

Hope this helps.... Hey this isn't one of the easy questions so I'm giving this code away in the hope that you'll adjust the points to at least 100 ;)... are we cool??

Good Luck!!


Author Comment

ID: 1525257
Viktornet, if it works I'll increase the points.  I know how to use the cancel command, but that doesn't work for some reason because I used the api to hide the desktop.  I do know what I am doing, but thought there might be some api call to just not allow the user to hit alt-f4...I have disabled everything else on the machine in code, alt-ctrl-del, start button, so on and so on....and when I hid the desktop by sending the hide command to it's hwnd, somehow, it allowed the user to hit alt-f4 to shut the system down...if I just disable the desktop then the user can right click on it and bring up that menu, which will allow them to create a shortcut on the desktop, and even though the shortcut won't run, they can run a program from the explorer box that creates the shortcut, anyhow, not sure if I explained anything well enough...but there it is.  I can use the registry to disable it all the time, but wanted something dynamic that would work without a reboot...the only reason I even care about the shutdown box coming up is that it will alow them to shutdown to a dos prompt which I can't have.  I also know there is a registry setting to disable that as well, but like I said, I really want it to be dynamic.  All the rest of the security in my program is dynamic and works sweet, till I found this damn little bug.  Hopefully your way will work.  Thanks for all your help...had I known it would have been harder I would have given more points, but figured it might just be something quick that I didn't know.  Heres one more question while I am here, if you answer a question and get the points, those points become expert points, but they can't be used towards regular points?  I have to collect 5 per day or buy more, that's the only way?  What good do expert points do then?  Or am I missing something...
LVL 10

Expert Comment

ID: 1525258
Okay... here are some answers to your questions and stuff...

I tested the program so I know it works on a Win9x machines...

about the points...

expert points are different than the one you everyday for questions asking... the experts points are just to show that you know what you're talking abourt... some people use E-E as a reference for job interview, etc.. that's what I did a few weeks ago.. that's why I wouldn't like to see my grades low simply because the user feels like giving me a B or a C or a D for an EXCELLENT answer... that's what I hate the most.. if it works then you give an A if it doesn't you ask for more details and code.. if the expert can't supply those, then you reject... sometimes you would have to take what you have and not try to do impossible things...

btw, this question is consider middle level simply because not all people know how to subclass and ****... so that's why you should give a good amount of points to the people who try to put effeorts into something in order to help the person who needs help.. just remember that no one in here is being paid.. E-E makes money because people can buy points and from advertisments, but experts get nothing in exchange...

if you have more questions please ask..

LVL 10

Expert Comment

ID: 1525259
sharmon, did it work?

Author Comment

ID: 1525260
It works, just finally got time to try it...sorry about the wait.  I owe you 30 points...have to purchase some more...I'll just make a post for you....I am sure you are fine with that correct...?
LVL 10

Expert Comment

ID: 1525261
hey, that's okay... no need to purchase points... 70 points is enough.. thanks!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

715 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