Ver Mensaje Individual
  #4  
Antiguo 06-04-2006
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 29
Lepe Va por buen camino
Código Delphi [-]
function TFrmteclas.ShutDownWindows(Flag: Word): Boolean;
var
  TokenPriv: TTokenPrivileges;
  H:         DWord;
  HToken:    THandle;
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
    OpenProcessToken(GetCurrentProcess,
      TOKEN_ADJUST_PRIVILEGES, HToken);
    LookUpPrivilegeValue(NIL, 'SeShutdownPrivilege',
      TokenPriv.Privileges[0].Luid);
    TokenPriv.PrivilegeCount := 1;
    TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    H := 0;
    AdjustTokenPrivileges(HToken, FALSE,
      TokenPriv, 0, PTokenPrivileges(NIL)^, H);
    CloseHandle(HToken);
  end;
  Result := ExitWindowsEx(Flag, 0);
end;

Opciones:
Código Delphi [-]
  ShutDownWindows(EWX_POWEROFF); // apagar windows
  ShutDownWindows(EWX_REBOOT); // reiniciar windows

  ShutDownWindows(EWX_POWEROFF or EWX_FORCE); // forzar apagado
  ShutDownWindows(EWX_REBOOT or EWX_FORCE); // forzar reiniciado

  shutdownwindows(EWX_LOGOFF); // cerrar session

Con la opción "Forzar" ningun programa puede denegar el apagado del sistema. Si hay cambios que no se han guardado en Word, directamente se pierden

Probado en Windows XP Sp2

Saludos
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita