ExitWindowsEx (aygshell)
Last changed: anonymous

.
Summary
This function shuts down the system

C# Signature:

[DllImport("aygshell.dll", SetLastError=""true"")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx([MarshalAs(UnmanagedType.U4)]uint dwFlags, [MarshalAs(UnmanagedType.U4)]uint dwReserved);

[DllImport("aygshell.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx([MarshalAs(UnmanagedType.U4)] ExitWindowsAction uFlags, [MarshalAs(UnmanagedType.U4)] uint dwReserved);

VB Signature:

Declare Function ExitWindowsEx Lib "aygshell.dll" (ByVal dwFlags As Integer, ByVal dwReserved As Integer) As Boolean

User-Defined Types:

enum ExitWindowsAction : uint

    {
    EWX_LOGOFF = 0,
    EWX_SHUTDOWN = 1,
    EWX_REBOOT = 2,
    EWX_FORCE = 4,
    EWX_POWEROFF = 8
    }

Alternative Managed API:

There is no alternative managed API function

Notes:

Parameters:

    uFlags
        Specifies the type of shutdown. This parameter must be one of the following values:
        EWX_POWEROFF - Shuts down the system and turns off the power. ""Note:"" This flag is not supported on a Windows Mobile-based Pocket PC.
        EWX_REBOOT - Shuts down the system and reboots.
    dwReserved
        Reserved; this parameter is ignored

Tips & Tricks:

Available only at Windows Mobile 5.0 or later. The ExitWindowsEx function returns as soon as it has initiated the shutdown. The shutdown then proceeds asynchronously. 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.

Sample Code:

static void Main(string[] args)

{

    ExitWindowsEx(ExitWindowsAction.EWX_REBOOT, 0);

}

Documentation