Function - ExitWindows or LogOffWindows

Moonshine

Registered User.
Local time
Today, 22:55
Joined
Jan 29, 2003
Messages
125
I manged to finally sort out the code that lets you logoffwindows by running a function, this is the module called WinExit, then behind the button you want to use, you just put Run "LogOffWindows" and this one works fine :):

Option Compare Database

Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As _
Long, ByVal dwReserved As Long) As Long

Function LogOffWindows()
'This will quit all applications and shut down Windows.
Dim x As Long
x = ExitWindowsEx(0, 0)
Application.Quit acExit
End Function

But, this one doesnt:

Option Compare Database

Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As _
Long, ByVal dwReserved As Long) As Long

Function ShutDownWindows()
'This will quit all applications and shut down Windows.
Dim x As Long
x = ExitWindowsEx(1, 0)
Application.Quit acExit
End Function


The only thing that has changed is the (0,0) which is changed to (1,0) which is supposed to ShutDown windows... yet it doesnt. It quits teh application fine, but will not shut down :(

Can anyone spoke a mistake with the code?
 
Here's what the uflags are:

uFlags
Specifies the type of shutdown. This parameter must be some combination of the following values:

EWX_FORCE
Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.

EWX_LOGOFF
Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.

EWX_POWEROFF
Shuts down the system and turns off the power. The system must support the power-off feature.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
Windows 95: Security privileges are not supported or required.

EWX_REBOOT
Shuts down the system and then restarts the system.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
Windows 95: Security privileges are not supported or required.

EWX_SHUTDOWN
Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

Windows 95: Security privileges are not supported or required.


I don't know which Index applies to each but you can experiment with the value to pass to the ExitWindowsEx function. A value between 0 & 4 might do the trick. And you can eliminate 0 & 1 as you have 0 working on your first function and you say 1 doesn't do what you want.
 
Hrmm it seems that you are right.... I have tried a few different numbers and it still wont shut down...

Really not sure why :( Im using NT4 and it says it is supported.
 
Could be your NT supports it but your hardware does not.
 
Hardware in what sense?

These are 2 week old computers.... P4 2.6ghz or does that not matter in this instance?
 
Ah - two weeks old certainly ought to be able to power down. I'm really getting in over my head now. You might check the Start>Shut Down... choices to see if ShutDown is one of the choices. If it is, I can't explain why your code didn't work. If ShutDown is not a choice in the Shut Down dialog, maybe the BIOS is set to disable it or some such. Sorry I can't help more.
 

Users who are viewing this thread

Back
Top Bottom