Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-10-30
7
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Accepted Solution

by:
gmayo earned 500 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 500 total points
ID: 9659783
Hi,

Try CopyFileEx.

HTH,

Andrew
0
 
LVL 3

Assisted Solution

by:fibdev
fibdev earned 500 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 500 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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