Consultor Eletrônico



Kbase 17126: How to Call WIN32 API Function: ExitWindowsEx
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
How to Call WIN32 API Function: ExitWindowsEx

DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.

INTRODUCTION:
=============
The following sample code show how to call the Win32 API function
called ExitWindowsEx. This function shuts down all applications in an
orderly fashion and either logs off, shuts down, or shuts down and
restarts the system.

This code has been tested on Windows NT 4.0 Workstation only.


/*-----------------------------------------------------------------*/
/* This API call can be extremely dangerous so be sure that you */
/* understand what it does before you use it. Oh, and remember to */
/* save all of your files before running the code. */
/*-----------------------------------------------------------------*/

EWX_LOGOFF = Shuts down all applications for the current user, then
logs off the user.

EWX_SHUTDOWN = Shuts down the system to where it is sage to turn off
the power. For Windows NT, the application must have
the SE_SHUTDOWN_NAME privilege.

EWX_REBOOT = Shuts down the system and then restarts the system.
For Windows NT, the application must have the
SE_SHUTDOWN_NAME privilege.

EWX_FORCE = Force processes that don't respond to terminate.

EWX_POWEROFF = Shuts down the system and turns off the power. The
system must support the power-off feature. For
Windows NT, the application must have the
SE_SHUTDOWN_NAME privilege.

&GLOBAL-DEFINE EWX_LOGOFF 0
&GLOBAL-DEFINE EWX_SHUTDOWN 1
&GLOBAL-DEFINE EWX_REBOOT 2
&GLOBAL-DEFINE EWX_FORCE 4
&GLOBAL-DEFINE EWX_POWEROFF 8

DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

PROCEDURE ExitWindowsEx EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intOptions AS LONG.
DEFINE INPUT PARAMETER intReserved AS LONG.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.

RUN ExitWindowsEx (INPUT {&EWX_LOGOFF}, INPUT 0, OUTPUT intResult).

IF intResult = 1 THEN
MESSAGE "Orderly Shutdown Started" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "Function Failed. Not Sure Why" VIEW-AS ALERT-BOX.

Progress Software Technical Support Note # 17126