用delphi检测磁盘写保护,请帮帮忙!(100分)

  • 主题发起人 主题发起人 lean
  • 开始时间 开始时间
L

lean

Unregistered / Unconfirmed
GUEST, unregistred user!
用delphi检测磁盘写保护,要在磁盘中生成×。txt文件!
 
GetLastError<br><br>ERROR_WRITE_PROTECT
 
踹一下<br>Try
 
GetLastError的使用方法<br>//----------------------------------------------------------------------<br>{$I-}<br>//你的文件写入操作<br>if GetLatError=ERROR_WRITE_PROTECT then<br>&nbsp;begin<br>&nbsp; &nbsp;showmessage('A:盘写保护');<br>&nbsp; &nbsp;{$I+}<br>&nbsp; &nbsp;exit;<br>end; <br>{$I+}
 
一次写保护检测后,要是软驱中有盘是写保护的,去掉写保护后,再进行文件写入,会出现错误,<br>是I/0 19 错误,要是检测第一次是,软驱中的磁盘没有写保护的话,是可以正常写入的,<br>程序段:<br>&nbsp; &nbsp; AssignFile(bankfile,'A:/1.txt');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {$I-}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rewrite(bankfile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bbs:= getlasterror ;<br>&nbsp; &nbsp; &nbsp; if &nbsp;bbs=ERROR_WRITE_PROTECT then <br>&nbsp; &nbsp;begin<br>&nbsp; showmessage('A盘写保护没有打开!,无法生成!');<br>&nbsp; {$I+}<br><br>&nbsp;exit;<br>&nbsp;end;<br>&nbsp; &nbsp;{$I+}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Rewrite(bankfile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeln(bankfile,'0'+'0'+' ');<br><br>那位帮帮忙!谢谢!
 
多人接受答案了。
 
后退
顶部