Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problema con ExitWindowsEx (https://www.clubdelphi.com/foros/showthread.php?t=37790)

JoeyJordison 23-11-2006 00:28:42

Problema con ExitWindowsEx
 
Hola tengo un problema para apagr pcs bajo winxp y 2000, se que tengo que obtener los permisos para apagar la pc pero ya lo he hecho, y solo me cierra la sesión este es el código que tengo:

Código Delphi [-]
var
hToken: THANDLE;
tkp, tkDumb: TTokenPrivileges;
DumbInt: DWord;
begin
FillChar(tkp, sizeof(tkp), 0);
if not (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)) then
raise Exception.create('OpenProcessToken falló con el código ' +
inttostr(GetLastError));
LookupPrivilegeValue(nil, pchar('SeShutdownPrivilege'),tkp.Privileges[0].Luid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, false, tkp, sizeof(tkDumb), tkDumb,DumbInt);
if GetLastError <> ERROR_SUCCESS then
raise Exception.create('AdjustTokenPrivileges falló con el código ' +
inttostr(GetLastError));
if not ExitWindowsEx(EWX_POWEROFF, 0) then
raise Exception.create('ExitWindowsEx falló con el código ' +inttostr(GetLastError));
end;

pjmedina 23-11-2006 11:18:06

Prueba con esta funcion a ver que tal te va...

Código Delphi [-]
function 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;

La llamada a la función es:

Código Delphi [-]
ShutDownWindows(EWX_SHUTDOWN)

Suerte


La franja horaria es GMT +2. Ahora son las 08:56:12.

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