读取的数据存放到数据库中。具体程序如下: procedure TForm1.readlogExecute(Sender: TObject); var logfile: TextFile; logbak: TextFile; Str1: string; datestr,timestr:string; begin AssignFile(logbak,'c:\windows\ppplog.bak'); if not FileExists('c:\windows\ppplog.bak') then Rewrite(logbak) else Append(logbak); if not FileExists('c:\windows\ppplog.txt') then MessageDlg('日志文件不存在', mtInformation,[mbOk],0) else begin AssignFile(logfile, 'c:\windows\ppplog.txt'); Reset(logfile); if Eof(logfile) then begin ShowMessage('日志文件已为空'); Exit; end; Table1.Open; while not Eof(logfile) do begin Readln(logfile, Str1); {‘log opened’作为计时的起点} if Pos('log opened',Str1)< >0 then begin datestr:=copy(str1,1,10); timestr:=copy(str1,12,8); Table1.Append; Table1.FieldValues['begindate'] := StrToDate(datestr); Table1.FieldValues['begintime'] := StrToTime(timestr); Table1.Post; end; {‘log closed’作为计时的结束} if Pos('log closed',str1)< >0 then begin datestr:=copy(str1,1,10); timestr:=copy(str1,12,8); table1.Last; table1.Edit; Table1.FieldValues['enddate'] := StrToDate(datestr); Table1.FieldValues['endtime'] := StrToTime(timestr); Table1.Post; end; Writeln(logbak,str1); end; Table1.close; Rewrite(logfile); CloseFile(logfile); CloseFile(logbak); end; end;
|---------|-----------|-|---------------------|
12-19-1998 21:54:31.25
- Microsoft 拨号网络适配器日志已打开。
12-19-1998 21:54:31.25
- 服务器类型是 PPP (点到点协议)。
.
.
.
12-19-1998 22:44:49.08
- Microsoft 拨号网络适配器日志已关闭。---- 上述内容是简体中文Windows 98的ppplog.txt文件格式,对于Windows 95,基本格式是一样的,只是事件部分是英文的。 日期 时间 发生的事件
|---------|-----------|-|---------------------|
12-15-1998 16:34:27.71
- Remote access driver log opened.
12-15-1998 16:34:27.71
- Installable CP VxD SPAP is loaded
12-15-1998 16:34:27.71
- Server type is PPP (Point to Point Protocol).
.
.
.
12-15-1998 16:58:30.05
- Remote access driver log closed.
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
var
logfile: TextFile;
logbak: TextFile;
Str1: string;
datestr,timestr:string;
begin
AssignFile(logbak,'c:\windows\ppplog.bak');
if not FileExists('c:\windows\ppplog.bak') then
Rewrite(logbak)
else
Append(logbak);
if not FileExists('c:\windows\ppplog.txt') then
MessageDlg('日志文件不存在',
mtInformation,[mbOk],0)
else
begin
AssignFile(logfile, 'c:\windows\ppplog.txt');
Reset(logfile);
if Eof(logfile) then
begin
ShowMessage('日志文件已为空');
Exit;
end;
Table1.Open;
while not Eof(logfile) do
begin
Readln(logfile, Str1);
{‘log opened’作为计时的起点}
if Pos('log opened',Str1)< >0 then
begin
datestr:=copy(str1,1,10);
timestr:=copy(str1,12,8);
Table1.Append;
Table1.FieldValues['begindate']
:= StrToDate(datestr);
Table1.FieldValues['begintime']
:= StrToTime(timestr);
Table1.Post;
end;
{‘log closed’作为计时的结束}
if Pos('log closed',str1)< >0 then
begin
datestr:=copy(str1,1,10);
timestr:=copy(str1,12,8);
table1.Last;
table1.Edit;
Table1.FieldValues['enddate']
:= StrToDate(datestr);
Table1.FieldValues['endtime']
:= StrToTime(timestr);
Table1.Post;
end;
Writeln(logbak,str1);
end;
Table1.close;
Rewrite(logfile);
CloseFile(logfile);
CloseFile(logbak);
end;
end;
可以使用定时器,不停的监测当前计算机时不是连入internet,
就可以取得拨号时间了,
我记得有个这样的函数,但是忘了,