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;
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
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.