Delphi...

Shutdown window

procedure ExitWindows32(ShutDownFlag: Word);

function ChangeNTSecurityForShutdown: Boolean;

var

hToken : THandle;

tkp,

Newt : TTokenPrivileges;

retlength : DWORD;

begin

Result := False;

if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES +

TOKEN_QUERY, hToken) <> False then

begin

{ Get the LUID for shutdown privilege }

if LookupPrivilegeValue( nil, 'SeShutdownPrivilege',

tkp.Privileges[0].Luid) = True then

begin

tkp.PrivilegeCount := 1; // One to set

tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

{ Get shutdown privilege for this process }

Result := AdjustTokenPrivileges(hToken, False, tkp,

SizeOf(TTokenPrivileges), Newt, retlength);

end;

end;

end;

begin

if GetWindowsVersion = VER_PLATFORM_WIN32_NT then

begin

if ChangeNTSecurityForShutdown then

ExitWindowsEx(ShutDownFlag, 0)

else

MessageDlg('Khong the shutdown.', mtError, [mbOK], 0);

end

else

if GetWindowsVersion = VER_PLATFORM_WIN32_WINDOWS then

ExitWindowsEx(ShutDownFlag, 0);

end;

Quay về trang chủ

Hosted by www.Geocities.ws

1