unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
function ExitWin(flag:word): Boolean;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.ExitWin(flag:word): Boolean;
var vi : TOSVersionInfo;
hToken : THandle;
tp : TTokenPrivileges;
h : DWord;
begin
//result := false;
vi.dwOSVersionInfoSize:=SizeOf(vi);
GetVersionEx(vi);
if vi.dwPlatformId = VER_PLATFORM_WIN32_NT
then // Windows NT
begin
// Achtung bei Delphi 2 muß @hToken stehen ... !!!! ?????
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,hToken);
LookupPrivilegeValue(
nil,'
SeShutdownPrivilege',
tp.Privileges[0].Luid);
tp.PrivilegeCount := 1;
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
h := 0;
AdjustTokenPrivileges(hToken,False,
tp,0,PTokenPrivileges(
nil)^,h);
CloseHandle(hToken);
result := ExitWindowsEx(flag,0);
end
else // Windows 95
begin
Result := ExitWindowsEx(flag,0);
end;
end;
//Abmelden:
procedure TForm1.Button1Click(Sender: TObject);
begin
ExitWin(EWX_LOGOFF);
end;
//Neustart:
procedure TForm1.Button2Click(Sender: TObject);
begin
ExitWin(EWX_REBOOT);
end;
//Shutdown:
procedure TForm1.Button3Click(Sender: TObject);
begin
ExitWin(EWX_SHUTDOWN);
end;
end.