How to make a copy of file thath are in use by the system

Hello  Experts,

I need know if exists any way to make a copy  of file thath are in use by windows (with delphi app) , like the files in <windowsdir>/system32/config and others.

Thanks in advance.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Depends whether the file is open with denied access, in which case you can't. If it is shared access then you should be able to open it in read-only mode. If you are trying to use AssignFile, Reset etc then you need to set the FileMode variable to 0 (read-only). By default it is 2 (read-write) which fails when trying to open a file that is in use.

Does CopyFile not work?

Geoff M.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I guess you simply want to copy password/security files like sam, security, system, default ets.? Am I right?

Try CopyFileEx.


this may or may not work, but you can try...

procedure TForm1.DoCopy(Source, Dest: string);
  SrcFile : Integer;
  DestFile : Integer;
  S : string;
  RetCode : Longint;
  OpenFileBuf   : TOFStruct;
  FName : array[ 0..255 ] of Char;
  StrPCopy( FName, Source );
  SrcFile := LZOpenFile( FName, OpenFileBuf, of_Read );
  StrPCopy( FName, Dest );
  DestFile := LZOpenFile( FName, OpenFileBuf, of_Create );

  RetCode := LZCopy( SrcFile, DestFile );
  if RetCode >= 0 then
    LZClose( SrcFile );
    LZClose( DestFile );
    Str( RetCode, S );
    MessageDlg( 'Could not copy ' + Source + ' to ' +
                Dest + #13 + 'Error Code = ' + S, mtError, [mbOk], 0 );
CopyFile('TargetFile', 'NewFileName', False);  // The false is for 'Fail if exists'

If I am not mistaken, CopyFile works perfectly fine on files that are in use.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.