unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Bevel1: TBevel;
Label3: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Label4: TLabel;
Edit3: TEdit;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Label5: TLabel;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
procedure AdjustToken;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.AdjustToken();
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkpPrivilegeCount : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess;
OpenProcessToken(hdlProcessHandle,
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),
hdlTokenHandle);
// Get the LUID for shutdown privilege.
LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
Privilege[0].Luid := tmpLuid;
Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1; // One privilege to set
tkp.Privileges[0] := Privilege[0];
// Enable the shutdown privilege in the access token of this
// process.
AdjustTokenPrivileges(hdlTokenHandle,
False,
tkp,
Sizeof(tkpNewButIgnored),
tkpNewButIgnored,
lBufferNeeded);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Clear ;
edit2.Clear ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if (edit1.Text='') then
begin
showmessage('对不起,帐号不能为空!') ;
edit1.Focused ;
end
else if (edit2.Text ='') then
begin
showmessage('对不起,密码不能为空!') ;
edit2.Focused ;
end
else
begin
if ((edit1.Text='typein') and (edit2.Text='meguess')) then
begin
groupbox1.Visible :=false ;
pagecontrol1.Visible :=true;
end
else
begin
showmessage('对不起,您无权使用本系统');
end
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
AdjustToken;
ExitWindowsEx(( EWX_FORCE ), $FFFF);
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
AdjustToken;
ExitWindowsEx(( EWX_REBOOT ), $FFFF);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
AdjustToken;
ExitWindowsEx(( EWX_SHUTDOWN ), $FFFF);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var shuttime: TDateTime;
begin
shuttime:=Now;
if (TimeToStr(shuttime)='23:49:11') or (TimeToStr(shuttime)='23:49:12')then
begin
AdjustToken;
ExitWindowsEx(( EWX_FORCE ), $FFFF);
end
end;
end.