Ver Mensaje Individual
  #6  
Antiguo 14-10-2005
bustio bustio is offline
Miembro
 
Registrado: oct 2003
Posts: 231
Reputación: 23
bustio Va por buen camino
tal vez te sirva

Hola:
He desarrollado una Unit que realiza el Restart y el LogOff de cualquier Windows(probado hasta el XPSP1) y a mi me funciona a las mil maravillas. Aqui te mando el codigo de mi clase.. Espero te sirva y me des tus comentarios.
Siempre para ayudar...

Código Delphi [-]
 unit uShutDown;
 {
     clae que apaga cualquier sistema operativo familia Windows.
     Probado hasta el WinXPSP1.
     Autor: Lazaro Bustio Martinez
                  Estudiante Ing. Informatica, 5to anno.
                  Cujae - CUBA
                  [email protected]
              
              NOTA: Mucha de las cosas aqui  mostrada no hubiesen sido posible
              sin la ayuda del foro de www.clubdelphi.com.. a todos ellos
              MUCHAS GRACIASSS!!!
 
 }
 
 interface
 uses
   Windows,SysUtils, Variants, Classes;
 
 Type
   TShutDownSystem = Class(TObject)
     Public
       Procedure EnableShutDown;
       Function  IsWinNT : boolean;
       Procedure ShutDownNT(Force : Boolean);
       Procedure RebootNT(Force : Boolean);
       Procedure LogOffNT(Force : Boolean);
       Constructor Create;
       Destructor Destroy;
      end;
 
 implementation
 
 { TShutDownSystem }
 function GetCurrentProcess: THandle;stdcall;external 'kernel32.dll';
 function OpenProcessToken(ProcessHandle: THandle; DesiredAccess: DWord; 
   TokenHandle: PHandle): bool;stdcall;external 'advapi32.dll'
 
 constructor TShutDownSystem.Create;
 begin
   Inherited Create;
 end;
 
 destructor TShutDownSystem.Destroy;
 begin
   Inherited Destroy;
 end;
 
 procedure TShutDownSystem.EnableShutDown;
 var
   hProc    : THandle;
   hToken   : THandle;
   mLUID    : Int64;
   mPriv    : TOKEN_PRIVILEGES;
   mNewPriv : TOKEN_PRIVILEGES;
   mVar     : DWord;
 begin
   hProc := GetCurrentProcess;
   OpenProcessToken(hProc,TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY,@hToken);
   LookupPrivilegeValue(PChar(''),PChar('SeShutDownPrivilege'),mLUID);
   mPriv.PrivilegeCount := 1;
   mPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
   mPRiv.Privileges[0].LUID := mLUID;
   mVar := 4 + (12 * mNewPriv.PrivilegeCount);
   AdjustTokenPrivileges(hToken,false, mPriv,4+12 * mPriv.PrivilegeCount,mNewPriv,mVar);  
 end;
 
 function TShutDownSystem.IsWinNT: boolean;
 var
   myOS : OSVERSIONINFO;
 begin
   myOS.dwOSVersionInfoSize := sizeOf(myOS);
   GetVersionEx(myOS);
   IsWinNT := (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT); 
 
 end;
 
 procedure TShutDownSystem.LogOffNT(Force: Boolean);
 var
   Flags : LongInt;
 begin
   Flags := EWX_LOGOFF;
   If Force then Flags :=  Flags + EWX_FORCE;
   If IsWinNT then EnableShutDown;
   ExitWindowsEx(Flags,0);
 end;
 
 procedure TShutDownSystem.RebootNT(Force: Boolean);
 var
   Flags : LongInt;
 begin
   Flags := EWX_REBOOT;
   If Force then Flags :=  Flags + EWX_FORCE;
   If IsWinNT then EnableShutDown;
   ExitWindowsEx(Flags,0);
 end;
 
 procedure TShutDownSystem.ShutDownNT(Force: Boolean);
 var
   Flags : LongInt;
 begin
   Flags := EWX_SHUTDOWN;
   If Force then Flags :=  Flags + EWX_FORCE;
   If IsWinNT then EnableShutDown;
   ExitWindowsEx(Flags,0);
 
 end;
 
 end.
__________________
Muchas Gracias...

Última edición por dec fecha: 14-10-2005 a las 17:49:49. Razón: Ajustar el ancho del texto.
Responder Con Cita