Link to home
Start Free TrialLog in
Avatar of geoka
geoka

asked on

shutdown/reboot win nt4

how to do ?

yours,
geoka

--------------------------
http://www.line.at
ASKER CERTIFIED SOLUTION
Avatar of daniel_c
daniel_c

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jaymol
Jaymol

That doesn't work in NT - only works in Windows 9x.

You need this really...

unit ExitWin;
 
interface
 
uses
  Windows;
 
function PlatformNT : boolean;
function ExitWindowsF(uFlags : word) : boolean;

implementation

const
  ANYSIZE_ARRAY    = 1;
  SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';

var
  IsNT : boolean;

function PlatformNT : boolean;
begin
  PlatformNT:=IsNT;
end;

function ExitWindowsNT(uFlags : word) : boolean;
var
  hToken : THandle;
  ptkp, ptkpold : PTokenPrivileges;
  r : dword;
begin
  if OpenProcessToken(GetCurrentProcess,
{$IFDEF DELPHI2}
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, @hToken) then
{$ELSE}
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
{$ENDIF}
  begin
    GetMem(ptkp,sizeof(TTOKENPRIVILEGES) +
      (1-ANYSIZE_ARRAY) * sizeof(TLUIDANDATTRIBUTES));
    LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME,
      ptkp^.Privileges[0].Luid);
    ptkp^.PrivilegeCount:=1;
    r:=0;
    ptkpold:=nil;
    if AdjustTokenPrivileges(hToken, false, ptkp^, 0, ptkpold^, r) then       ExitWindowsNT:=ExitWindowsEx(uFlags,0);
  end;
  ExitWindowsNT:=GetLastError=ERROR_SUCCESS;
end;

function ExitWindowsF(uFlags : word) : boolean;
begin
  if IsNT then ExitWindowsF:=ExitWindowsNT(uFlags)
  else ExitWindowsF:=ExitWindowsEx(uFlags,0);
end;
 
procedure CheckOS;
var
  VerInfo : TOSVersionInfo;
begin
  IsNT:=false;
  VerInfo.dwOSVersionInfoSize:=sizeof(VerInfo);
  if (GetVersionEx(VerInfo)) then
    IsNT:=VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT;
end;

begin
  CheckOS;
end.

Save that as a unit, put it in your uses clause, and away you go!  (Works on any windows platform.)

John.
Avatar of geoka

ASKER

ok. thx for amswers but can't try in next week so you must wait a few days for your points.

yours,
geoka
Avatar of geoka

ASKER

uuhhh (Edited by Computer101), i wanted to deliver the points to jaymol. may you give the points daniel_c, i'm afraid, but only his comment worked under NT.