Solved

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

Posted on 2003-10-30
7
195 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now