告诉您的位置:首页 > 资讯中心 > 防护技巧 > 正文 |
 |
| Delphi:自己编程实现对CIH病毒的预防 |
| 2001年06月05日16:10:24 中国程序员网 |
[an error occurred while processing this directive]
席卷全球的CIH病毒以其巨大的破坏性,使人谈“C”色变。由于该病毒直接威胁到大家爱“鸡”的“人身”(硬件)安全,于是乎有钱的纷纷“出血”购买以前不屑一顾的正版杀毒软件,而没钱的也不敢再相信D版,老老实实地跳过每月的26日,或者干脆停机不用,本人就是属于后者的“停机一族”。可是由于我向来是“只记星期不记日”,以致数次都是与“死亡”擦肩而过。于是就用Delphi写了下面的小程序,以便提醒我更改日期,保护我爱“鸡”的生命安全。
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 :string;
Day :string[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;
[iduba_page] 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日,就会提醒你更改日期,否则结束运行,并不驻留内存和占用系统资源。有兴趣的朋友也可以再添加一个按钮,直接更改日期,笔者在此就不详细讨论了。欢迎您来信与我交流,我的Email地址是:zhangzhen@263.net。
控件 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] [2] 【】 |
|
[an error occurred while processing this directive]
|