Author: William Gerbert
I want to copy the SYSTEM.DAT and USER.DAT files from the Windows directory. If I
copy them using Explorer, manually, they copy fine. But, from Delphi 4 on Windows
95, using the CopyFile function, I get an access denied error.
Answer:
The registry files are always open, and it appears that the CopyFile API function
doesn't use the appropriate sharing flags when it tries to copy them. This function
should do the trick for you:
1 procedure CopyRegistryFile(const Source, Dest: string);
2 var3 SourceStream, DestStream: TFileStream;
4 begin5 SourceStream := TFileStream.Create(Source, fmOpenRead + fmShareDenyNone);
6 try7 DestStream := TFileStream.Create(Dest, fmCreate);
8 try9 DestStream.CopyFrom(SourceStream, SourceStream.Size);
10 finally11 DestStream.Free
12 end;
13 finally14 SourceStream.Free
15 end;
16 end;