![]() |
|
Delphi:自己编程实现对CIH病毒的预防 - 打印版本 +- MyTFLS社区 (https://community.mytfls.com) +-- 论坛: 电脑区 (https://community.mytfls.com/forum-19.html) +--- 论坛: 系统+网络+硬件 (https://community.mytfls.com/forum-20.html) +--- 主题: Delphi:自己编程实现对CIH病毒的预防 (/thread-248.html) |
Delphi:自己编程实现对CIH病毒的预防 - 比电子小 - 2004-2-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 tring; Day tring[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 缺省 缺省 |