什么是I/O error 103(50分)

  • 主题发起人 主题发起人 浮生
  • 开始时间 开始时间

浮生

Unregistered / Unconfirmed
GUEST, unregistred user!
我编程修改msdos.sys文件,要屏蔽开机时的F8键,但有时出现I/O error 103错误。(有时正确)
我逐步跟踪,到了CloseFile(MyFile);时出错;
我的修改方法是将msdos.sys导入memo内,判断有没有BootKeys=0或BootKeys=1(一般都在文件尾)
没有就追加,有就修改。
程序如下:
///////////////////屏蔽F8///////////////////////
procedure NoF8;
var
MyFile:TextFile;
i,LineNum,Lnum:integer;
buffer:string;
begin
buffer:=GetWinDir;
buffer:=buffer[1];
assignFile(MyFile,buffer+':/msdos.sys');
reset(MyFile);
while not Eof(MyFile) do
begin
readln(MyFile,buffer);
form1.Memo1.Lines.Add(buffer);
end;
LineNum:=form1.memo1.lines.indexof('BootKeys=1');
lnum:=form1.memo1.lines.indexof('BootKeys=0');
CloseFile(MyFile);
if (LineNum<>0) and (LineNum<>-1) then
try
rewrite(MyFile);
for i:=0 to (LineNum-1) do
begin
buffer:=form1.memo1.lines;
writeln(MyFile,buffer);
end;
writeln(MyFile,'BootKeys=0');
finally
CloseFile(MyFile);
end
else
try
if (lnum=0) or (lnum=-1) then
begin
append(MyFile);
writeln(MyFile,'BootKeys=0');
end;
finally
CloseFile(MyFile); //此处出错

end;
end;
/////////////////////////F8启用//////////////////////////////////
procedure EnableF8;
var
MyFile:TextFile;
i,LineNum,lnum:integer;
buffer:string;
begin
buffer:=GetWinDir;
buffer:=buffer[1];
assignFile(MyFile,buffer+':/msdos.sys');
reset(MyFile);
while not Eof(MyFile) do
begin
readln(MyFile,buffer);
form1.Memo1.Lines.Add(buffer);
end;
LineNum:=form1.memo1.lines.indexof('BootKeys=0');
lnum:=form1.memo1.lines.indexof('BootKeys=1');
CloseFile(MyFile);
if (LineNum<>0) and (LineNum<>-1) then
try
rewrite(MyFile);
for i:=0 to (LineNum-1) do
begin
buffer:=form1.memo1.lines;
writeln(MyFile,buffer);
end;
writeln(MyFile,'BootKeys=1');
finally
CloseFile(MyFile);
end
else
try
if (lnum=0) or (lnum=-1) then
begin
append(MyFile);
writeln(MyFile,'BootKeys=0');
end;
finally
CloseFile(MyFile); //此处出错
end;
end;
 
文件没有打开。
if (LineNum<>0) and (LineNum<>-1) then
try
rewrite(MyFile);
for i:=0 to (LineNum-1) do
begin
buffer:=form1.memo1.lines;
writeln(MyFile,buffer);
end;
writeln(MyFile,'BootKeys=1');
finally
CloseFile(MyFile);
end
else
try
/////assia应该打开文件g
if (lnum=0) or (lnum=-1) then
begin
append(MyFile);
writeln(MyFile,'BootKeys=0');
end;
finally
CloseFile(MyFile); //此处出错
end;
 
procedure NoF8;
var
MyFile:TextFile;
i,LineNum,Lnum:integer;
buffer:string;
begin
buffer:=GetWinDir;
buffer:=buffer[1];
assignFile(MyFile,buffer+':/msdos.sys');
reset(MyFile);
while not Eof(MyFile) do
begin
readln(MyFile,buffer);
form1.Memo1.Lines.Add(buffer);
end;
LineNum:=form1.memo1.lines.indexof('BootKeys=1');
lnum:=form1.memo1.lines.indexof('BootKeys=0');
////////////////此处注释掉,此处的关闭会导致后面操作的文件没打开,问题已解决///////////////////
// CloseFile(MyFile);
if (LineNum<>0) and (LineNum<>-1) then
try
rewrite(MyFile);
for i:=0 to (LineNum-1) do
begin
buffer:=form1.memo1.lines;
writeln(MyFile,buffer);
end;
writeln(MyFile,'BootKeys=0');
finally
CloseFile(MyFile);
end
else
try
if (lnum=0) or (lnum=-1) then
begin
append(MyFile);
writeln(MyFile,'BootKeys=0');
end;
finally
CloseFile(MyFile); //此处出错

end;
end;
谢谢[:D]
 

Similar threads

I
回复
0
查看
573
import
I
I
回复
0
查看
671
import
I
I
回复
0
查看
508
import
I
I
回复
0
查看
419
import
I
后退
顶部