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); ShutDownWindows(EWX_REBOOT);
ShutDownWindows(EWX_POWEROFF or EWX_FORCE); ShutDownWindows(EWX_REBOOT or EWX_FORCE);
shutdownwindows(EWX_LOGOFF);
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