How do I shut down or restart windows from my ATEasy application?

Knowledge Base Article # Q200070

Read Prior Article Read Next Article
Summary Shuting down or restarting Windows from ATEasy
Solution:

To shut down or restart windows, You need to call a Windows API that is found in USER32.dll. The function is described here:

ExitWindowsEx(uFlags: Val DWord, dwReason: VAL DWord): Bool

Parameters
uFlags - [in] Shutdown type. This parameter must include one of the following values:

EWX_LOGOFF - 0 - Shuts down all processes running in the logon session of the process that called the ExitWindowsEx function. Then it logs the user off. This flag can be used only by processes running in an interactive user's logon session.

EWX_POWEROFF - 0x00000008 - Shuts down the system and turns off the power. The system must support the power-off feature. The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

EWX_REBOOT - 0x00000002 -  Shuts down the system and then restarts the system. The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

EWX_SHUTDOWN - 0x00000001 - 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. The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Specifying this flag will not turn off the power even if the system supports the power-off feature. You must specify EWX_POWEROFF to do this.
Windows XP SP1:  If the system supports the power-off feature, specifying this flag turns off the power.

This parameter can optionally include one of the following values:

EWX_FORCE - 0x00000004 -  Windows 2000/NT:  Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency. Starting with Windows XP, these messages will always be sent.

EWX_FORCEIFHUNG - 0x00000010 - Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message within the timeout interval. For more information, see the Remarks. Windows NT and Windows Me/98/95:  This value is not supported.

dwReason  - [in] Reason for initiating the shutdown. This parameter must be one of the system shutdown reason codes. If this parameter is zero, the SHTDN_REASON_FLAG_PLANNED reason code will not be set and therefore the default action is an undefined shutdown that is logged as "No title for this reason could be found". By default, it is also an unplanned shutdown. Depending on how the system is configured, an unplanned shutdown triggers the creation of a file that contains the system state information, which can delay shutdown. Therefore, do not use zero for this parameter. Windows 2000/NT and Windows Me/98/95:  This parameter is ignored.

Return Values
If the function succeeds, the return value is nonzero. Because the function executes asynchronously, a nonzero return value indicates that the shutdown has been initiated. It does not indicate whether the shutdown will succeed. It is possible that the system, the user, or another application will abort the shutdown.

See Also
  • See the ATEasy Getting Started manual for more information of how to define an call an external DLL function.
Article Date 3/21/2006 12:20:58 PM
Keywords ATEasy, ExitWindowsEx

0 ratings | 0 out of 5
Read Prior Article Read Next Article