Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   Apagar PC en XP (https://www.clubdelphi.com/foros/showthread.php?t=12926)

tiel 30-07-2004 23:17:00

Apagar PC en XP
 
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:

Código:


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;



La franja horaria es GMT +2. Ahora son las 09:20:23.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi