Solved

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

Posted on 2003-10-30
7
198 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:MauricioGaviria
7 Comments
 
LVL 8

Accepted Solution

by:
gmayo earned 125 total points
ID: 9656148
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.
0
 
LVL 4

Expert Comment

by:nestorua
ID: 9657309
HI,
I guess you simply want to copy password/security files like sam, security, system, default ets.? Am I right?
Sincerely,
Nestorua.
0
 
LVL 5

Assisted Solution

by:DeerBear
DeerBear earned 125 total points
ID: 9659783
Hi,

Try CopyFileEx.

HTH,

Andrew
0
 
LVL 3

Assisted Solution

by:fibdev
fibdev earned 125 total points
ID: 9664205
this may or may not work, but you can try...

procedure TForm1.DoCopy(Source, Dest: string);
var
  SrcFile : Integer;
  DestFile : Integer;
  S : string;
  RetCode : Longint;
  OpenFileBuf   : TOFStruct;
  FName : array[ 0..255 ] of Char;
begin
  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
  begin
    LZClose( SrcFile );
    LZClose( DestFile );
  end
  else
  begin
    Str( RetCode, S );
    MessageDlg( 'Could not copy ' + Source + ' to ' +
                Dest + #13 + 'Error Code = ' + S, mtError, [mbOk], 0 );
  end;
end;
0
 

Assisted Solution

by:unfunf
unfunf earned 125 total points
ID: 9761162
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question