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

x
?
Solved

How do I disable system shutdown?

Posted on 1999-07-16
12
Medium Priority
?
176 Views
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?
0
Comment
Question by:sharmon
[X]
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
12 Comments
 
LVL 7

Expert Comment

by:Vbmaster
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)

0
 
LVL 7

Expert Comment

by:Vbmaster
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?

0
 
LVL 6

Author Comment

by:sharmon
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

 

Expert Comment

by:lewsthern
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.
0
 
LVL 1

Expert Comment

by:rayford
ID: 1525254
Just Ideas..

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

Expert Comment

by:wylliker
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
 else
     cancel = True   ' not ready to quit
 end if

End Sub
0
 
LVL 10

Accepted Solution

by:
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 ;))

=========MODULE1.BAS========
Option Explicit

Public Const WM_QUERYENDSESSION = &H11
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
    If uMsg = WM_QUERYENDSESSION Then
        WindowProc = 0
    Else
        WindowProc = CallWindowProc(TheProc, hwnd, uMsg, wParam, lParam)
    End If
End Function

======FORM1.FRM=======
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!!

..-=ViKtOr=-..
0
 
LVL 6

Author Comment

by:sharmon
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...
0
 
LVL 10

Expert Comment

by:viktornet
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..

-vik-
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1525259
sharmon, did it work?
0
 
LVL 6

Author Comment

by:sharmon
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...?
0
 
LVL 10

Expert Comment

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

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