PDA

Ver la Versión Completa : Apagar PC en XP


tiel
30-07-2004, 23:17:00
Investigando ya sé cómo hacer que funcione la función API ExitWindowsEx en Windows XP, tienen que tener privilegios para eso, y se obtiene con la API también:



var

hToken: THandle;
tkp: TTokenPrivileges;
tkp2: PTokenPrivileges;
r: Dword; //Esta variable sobra, pero se tiene que usar para pasársela a la función AdjustToken....

implementation

if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then

if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then
begin

tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

if AdjustTokenPrivileges(hToken, FALSE, tkp, 0, nil, r) then
ExitWindowsEx( .. , 0 );
end;