I’d like to ask if anyone knows correct way how to load ntuser.dat file into registry on Windows7 or XP. I’ve been trying to accomplish that by using this code
_Reg := TRegistry.Create;
_Reg.RootKey := HKEY_USERS;
if (_Reg.Loadkey('Test2', 'C:\Users\Test2\NTUSER.DAT')) then
ShowMessage('User hive loaded');
_Reg.Unloadkey('Test2');
_Reg.CloseKey;
_Reg.Free;
Path to a file is correct and file exists. I’ve also tried to use function I found on the internet EnableNTPrivilege(‘SeRestorePrivilege’, SE_PRIVILEGE_ENABLED) for setting up privileges before trying to load a hive. And still I get false from _Reg.Loadkey.
I’ve also tried to use this function NTSetPrivilege(‘SeRestorePrivilege’, True) for setting up privileges. But this function returns error ‘Not all privileges or groups referenced are assigned to the caller’
The
TRegistry.LoadKeyfunction internally uses theRegLoadKeyfunction which requieres that the calling process have the SE_RESTORE_NAME and SE_BACKUP_NAME privileges. If the call to the function returns a value <> toERROR_SUCCESS (0)you must check theLastErrorand theLastErrorMsgproperties to get more info.Check this sample to see how the function must be called and how the result of the operation is handled.