Негарантированный ExitWindowsEx

From
slavik levchenko (2:4626/6.58)
To
Boris Rudakov ()
Date
2003-10-12T23:12:22Z
Area
CARBON.COPY
 * Forwarded from area 'SU.WINDOWS.PROG'
/re, Boris

28 сентября 2003 11:35, Boris Rudakov писал All:

 BR>   Flags = Forsed ? EWX_FORCE : 0;
 BR>   if (PowerOff) Flags |= EWX_POWEROFF;
 BR> ...
 BR>   if (!ExitWindowsEx(EWX_REBOOT | Flags, 0))
 BR>     ErrorHalt();
 BR>   printf(APPNAME " sequence initiated.\n");
 BR> ...

вот вырезки насчет XP и шутдауна:

EWX_SHUTDOWN
Windows NT/2000/XP:  The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

Windows NT/2000/XP:  To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information, see Running with Special Privileges.


а вот тебе пример:

BOOL MySystemShutdown()
{
   HANDLE hToken;
   TOKEN_PRIVILEGES tkp;

   // Get a token for this process.

   if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
      return( FALSE );

   // Get the LUID for the shutdown privilege.

   LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
        &tkp.Privileges[0].Luid);

   tkp.PrivilegeCount = 1;  // one privilege to set
   tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

   // Get the shutdown privilege for this process.

   AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
        (PTOKEN_PRIVILEGES)NULL, 0);

   if (GetLastError() != ERROR_SUCCESS)
      return FALSE;

   // Shut down the system and force all applications to close.

   if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
      return FALSE;

   return TRUE;
}


--- /icq 251037
 * Origin: [the nobodies] (2:4626/6.58)