Delphi:自己编程实现对CIH病毒的预防
#1
1.启动Delphi,新建一个工程,命名为cih.dpr。在空白窗体上添加三个StaticText标签、一个Label标签和一个按钮(Button)。它们的属性如下表:
  对于文本标签可以改变其Font属性,使其色彩醒目。
  2.添加一个TTimer控件,用以起到文字闪烁效果(此项可选)。其属性如下:
  控件 Name Enabled Interval
  Timer1 Timer1 False 500
  以下是程序实现部分:
  unit Unit1;
  interface
  uses Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls, ExtCtrls, ComCtrls;
  type
   TForm1 = class(TForm)
   laDate: TLabel;
   Timer1: TTimer;
   StaticText1: TStaticText;
   StaticText2: TStaticText;
   StaticText3: TStaticText;
   btExit: TButton;
   procedure FormCreate(Sender: TObject);
   procedure Timer1Timer(Sender: TObject);
   procedure FormShow(Sender: TObject);
   procedure btExitClick(Sender: TObject);
   private
   { Private declarations }
   public
   { Public declarations }
   end;
  const
   CIH_PREDATE=25; //定义为CIH病毒发作日期的前一天
  var
   Form1: TForm1;
   CanSee :Boolean; //“Warning”是否可见
   CanCloseForm :Boolean; //程序是否可以中止
  implementation
  {$R *.DFM}
  procedure Form1.FormCreate(Sender: TObject);
  var
   Today Confusedtring;
   Day Confusedtring[2];
  begin
   Today :=DateTimeToStr(Date); //获取当前日期
   Day :=Copy(Today,Length(Today)-1,2); //提取当前日期中的天数
   if StrToInt(Day)=CIH_DATE then
   begin
   CanCloseForm :=False;
   CanSee :=True;
   Timer1.Enabled :=True;
   laDate.Caption :=Today;
   end
   else
   CanCloseForm :=True;
  end;
  procedure TForm1.Timer1Timer(Sender: TObject);
  begin
   if CanSee then
   begin
   StaticText3.Visible :=False;
   CanSee :=False;
   end else
   begin
   StaticText3.Visible :=True;
   CanSee :=True;
   end;
  end;
  procedure TForm1.FormShow(Sender: TObject);
  begin
   if CanCloseForm then Close; //不是25日,则中止程序运行
  end;
  procedure TForm1.btExitClick(Sender: TObject);
  begin Close;
  end;
  end.
  此程序经过编译之后,生成名为cih.exe的可执行文件。手工将它加入Windows“开始”菜单的启动组,每次开机时程序就自动执行,只要到了每月的25日,就会提醒你更改日期,否则结束运行,并不驻留内存和占用系统资源

控件 Name Caption Left Top Width Height
  Form1 Form1 当心CIH病毒!!! 缺省 缺省 383 254
  StaticText1 StaticText1 今天是:  80 88  缺省 缺省
  StaticText2 StaticText2 当心 CIH 病毒!!! 40 120  缺省 缺省
  StaticText3 StaticText3 Warning!!!  48 8 缺省 缺省
  Label1 laDate CIH(任意)  192 82 缺省 缺省
  Button1 btExit 退出  200 184 缺省 缺省
回复


跳转到:


正在阅读该主题的用户: 1位游客
您的访问已通过Cloudflare保护,访问自美国/loc=US。