Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-11-2006
JoeyJordison JoeyJordison is offline
No confirmado
 
Registrado: oct 2006
Posts: 68
Poder: 0
JoeyJordison Va por buen camino
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;

Última edición por dec fecha: 23-11-2006 a las 05:42:29.
Responder Con Cita
  #2  
Antiguo 23-11-2006
pjmedina pjmedina is offline
Miembro
 
Registrado: abr 2006
Posts: 84
Poder: 18
pjmedina Va por buen camino
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
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
El ordenador no se apaga del todo con ExitWindowsEx() en Win2000 aram2r API de Windows 4 18-11-2008 18:39:38


La franja horaria es GMT +2. Ahora son las 04:44:19.


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
Copyright 1996-2007 Club Delphi