mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
源码类别:

Delphi/CppBuilder

开发平台:

Delphi

  1. unit mainunit;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls,Registry;
  6. type
  7.   TForm1 = class(TForm)
  8.     Label1: TLabel;
  9.     Label2: TLabel;
  10.     Button1: TButton;
  11.     Button2: TButton;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure Button1Click(Sender: TObject);
  14.     procedure Button2Click(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     procedure CanUseTaskMgr(Value:Boolean);
  19.     { Public declarations }
  20.   end;
  21. var
  22.   Form1: TForm1;
  23. implementation
  24. {$R *.dfm}
  25. procedure TForm1.CanUseTaskMgr(Value:Boolean);
  26. var
  27.  Reg:TRegistry;
  28. begin
  29.  Reg:=TRegistry.Create;
  30.  try
  31.   Reg.RootKey:=HKEY_CURRENT_USER;
  32.   if Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem', True) then
  33.      begin
  34.       Reg.WriteBool('DisableTaskMgr',Value);
  35.      end;
  36.   finally
  37.    Reg.CloseKey;
  38.    Reg.Free;
  39.   end;
  40. end;
  41. procedure TForm1.FormCreate(Sender: TObject);
  42. var
  43.  Reg:TRegistry;
  44. begin
  45.  Reg:=TRegistry.Create;
  46.  try
  47.   Reg.RootKey:=HKEY_CURRENT_USER;
  48.   if Reg.KeyExists('SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem') then
  49.    begin
  50.     Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem',False);
  51.     if Reg.ValueExists('DisableTaskMgr') then
  52.      begin
  53.       if (Reg.ReadBool('DisableTaskMgr')) then
  54.        begin
  55.         Label2.Caption:='否';
  56.         Button1.Enabled:=False;
  57.         Button2.Enabled:=True;
  58.        end
  59.        else
  60.        begin
  61.         Label2.Caption:='是';
  62.         Button1.Enabled:=True;
  63.         Button2.Enabled:=False;
  64.        end;
  65.      end
  66.      else
  67.      begin
  68.       Label2.Caption:='是';
  69.       Button1.Enabled:=True;
  70.       Button2.Enabled:=False;
  71.      end;
  72.    end
  73.    else
  74.    begin
  75.     Label2.Caption:='是';
  76.     Button1.Enabled:=True;
  77.     Button2.Enabled:=False;
  78.    end;
  79.  finally
  80.   Reg.CloseKey;
  81.   Reg.Free;
  82.  end; 
  83. end;
  84. procedure TForm1.Button1Click(Sender: TObject);
  85. begin
  86.  CanUseTaskMgr(True);
  87.  Label2.Caption:='否';
  88.  Button1.Enabled:=False;
  89.  Button2.Enabled:=True;
  90.  ShowMessage('任务管理器已经被禁止使用!');
  91. end;
  92. procedure TForm1.Button2Click(Sender: TObject);
  93. begin
  94.  CanUseTaskMgr(False);
  95.  Label2.Caption:='是';
  96.  Button1.Enabled:=True;
  97.  Button2.Enabled:=False;
  98.  ShowMessage('任务管理器已经被允许使用!');
  99. end;
  100. end.