各位大侠,你们好!
    现有一问题急需支援,请大家出出主意.
    以下这个函数是对DRV磁盘(U盘)进行直接写操作的函数,在XP下操作正常,但在VISTA下调试时出现CREATEFILE()函数已经正常执行了,但WRITEFILE()函数出错,用GETLASTERR()得到的错误事情为5--'拒绝访问',请各位大侠指教.我估计仍然是VISTA安全方面的限制造成的,但我已经用管理员登录系统,而且运行时,我已经把可执行程序的属性设置为:1.兼容XP 2;2.以管理员身份运行该程序,但仍然出现这样的问题,网上找了好多资料,也试用修改了CREATEFILE的参数,但始终没有找到解决的方法.///函数功能: 把缓冲区中blocks*512字节的内容写到指定磁盘(DRV)的指定扇区(LBA)开始的扇区中
function nt_Write(drv: byte; LBA: longint; blocks: byte; buf: pointer): boolean;
var
  str:string;
  ci:cardinal;
  hDevicehandle:THandle;
  st1,sc1:cardinal;
  re1:integer;
  sa:TSecurityAttributes;
begin
  result:=false;
      hDevicehandle:=createfile(pchar('\\.\PhysicalDrive'+inttostr(drv)),GENERIC_ALL,FILE_SHARE_write or FILE_SHARE_read,NIL,OPEN_EXISTING,0,0);
  if (hDevicehandle<>INVALID_HANDLE_VALUE) then
  begin
      sc1:= blocks;
         RE1:=FILESEEK(hDevicehandle,LBA*512,0);
         IF RE1=-1 THEN
         begin
            writekey('test','fileseek_err',syserrormessage(getlasterror()));
            result:=false;
            CLOSEHANDLE(hDevicehandle);
            exit;
         end;
         re1:= filewrite(hDevicehandle,buf^,sc1*512);
         if (re1=-1) or (re1<>sc1*512) then
         begin
            result:=false;
            writekey('test','filewrite_err',syserrormessage(getlasterror())+' return:'+inttostr(re1));
         end
         else
            result:=true;
           CLOSEHANDLE(hDevicehandle);
  end;
end;