How to copy the registry files (Views: 28)
Problem/Question/Abstract: 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: procedure CopyRegistryFile(const Source, Dest: string); var SourceStream, DestStream: TFileStream; begin SourceStream := TFileStream.Create(Source, fmOpenRead + fmShareDenyNone); try DestStream := TFileStream.Create(Dest, fmCreate); try DestStream.CopyFrom(SourceStream, SourceStream.Size); finally DestStream.Free end; finally SourceStream.Free end; end; |