Your code had the same result, it saves a file with 0byte in length.I changed that line to R.SaveKey('\Software\Borland', 'SavedKeyFile.reg');just to make sure that it may work, that Borland key does exist, but strangely nothing is saved!

You were right, that was because of access privilege,I wonder why saving a key to a file needs that privilege while reading, writing or even deleting a key within a program is done without that!!!Anyhow I fixed the problem by below codes, I pose it in here in case if someone is interested in this topic. I also mentioned a small useful function for moving a file to recycle bin , that is better than using DeleteFile function!

// This saves the key in binaro format, To read the // same key, set the privilege as above and use //R.RestoreKey('Software\MyKey', 'SavedKeyFile.reg') If R.SaveKey('Softare\MyKey', 'SavedKeyFile.reg') Then Begin //worked!!! Yippee!! woowoo!! Saved! End Else Begin //Sorry Failed! End; End; Finally R.Free; End;End;

I just noticed restoring that Registry key from a file is also a bit of head ache!Below function can restore a saved registry key from a file. Note that access privilege string is different from saving.

Procedure ReadMyKey;Var R: TRegistry;Begin R:= TRegistry.Create; try R.RootKey:= HKEY_CURRENT_USER; // the key must exist // do necessary checks R.OpenKey('Software\Mykey', True); R.CloseKey;// Do not forget to close the key SetAccessPrivilege('SerestorePrivilege',SE_PRIVILEGE_ENABLED); //This will overwtite all keys and values if they already exist If R.RestoreKey('Software\Mykey', 'SavedRegKey.reg') Then Begin //Done! Do needful End Else Begin // Something is wrong! //As I checked if the registry is open and if it exists and // it is selected by you, then this restore will fail End; Finally R.Free; End;End;