如题....

解决方案 »

  1.   

    AQC (Another Qaility Code):
    function ProtectFile(sFilename : string) : hFile;
    var
           hf: hFile;
           lwHFileSize, lwFilesize: longword;
           ofs : TOFStruct;
    begin
           if FileExists(sFilename) then
           begin
                   hf := OpenFile(pchar(sFilename), ofs, OF_READ or OF_WRITE or OF_SHARE_EXCLUSIVE);
                   if hf <> 0 then
                   begin
                           lwFilesize := GetFileSize(hf, @lwHFileSize);
                           if LockFile(hf, 0, 0, lwFilesize, lwHFilesize) then
                           Result := hf else Result := 0;
                   end
                   else Result := 0;
           end
           else Result := 0;
    end;function UnProtectFile(hf: hFile): boolean;
    begin
           if hf <> 0 then
           CloseHandle(hf);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
           protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
           if protectedFile = 0 then
           MessageBox(Handle, 'Error locking file!', '', MB_OK or MB_ICONERROR) else
           Button1.Enabled := False;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
           plik: TextFile;
           data: string;
    begin
           UnProtectFile(protectedFile);       AssignFile(plik, 'test.txt');
           Reset(plik);
           Read(plik, data);
           CloseFile(plik);       protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
           ShowMessage(data);
    end;
      

  2.   

    没啥作用
    DOS下搞定你独占打开?不就用不了?这好吗?API Hook?Windows下有用而已http://lysoft.7u7.net
      

  3.   

    用NTFS分区格式,设置文件权限。就基本上够用了。
      

  4.   

    AQC (Another Qaility Code):
    function ProtectFile(sFilename : string) : hFile;
    var
           hf: hFile;
           lwHFileSize, lwFilesize: longword;
           ofs : TOFStruct;
    begin
           if FileExists(sFilename) then
           begin
                   hf := OpenFile(pchar(sFilename), ofs, OF_READ or OF_WRITE or OF_SHARE_EXCLUSIVE);
                   if hf <> 0 then
                   begin
                           lwFilesize := GetFileSize(hf, @lwHFileSize);
                           if LockFile(hf, 0, 0, lwFilesize, lwHFilesize) then
                           Result := hf else Result := 0;
                   end
                   else Result := 0;
           end
           else Result := 0;
    end;function UnProtectFile(hf: hFile): boolean;
    begin
           if hf <> 0 then
           CloseHandle(hf);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
           protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
           if protectedFile = 0 then
           MessageBox(Handle, 'Error locking file!', '', MB_OK or MB_ICONERROR) else
           Button1.Enabled := False;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
           plik: TextFile;
           data: string;
    begin
           UnProtectFile(protectedFile);       AssignFile(plik, 'test.txt');
           Reset(plik);
           Read(plik, data);
           CloseFile(plik);       protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
           ShowMessage(data);
    end;
      

  5.   

    to : ly_liuyang(Liu Yang) 
    那当然是在windows下,在DOS下有啥意义;
    硬盘分区当然尽可能是NTFS的,以免人拿去挂DOS下面。