I'm use reg->SaveKey("Software", "D:\1.reg"). But getting empty file, without data.
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TRegistry *reg=new TRegistry(KEY_READ);
reg->RootKey=HKEY_LOCAL_MACHINE;
reg->OpenKey("Software",0);;
reg->SaveKey("Software","D:\\1.reg");
delete reg;
}
SaveKey
is a loose wrapper around RegSaveKey()
, the documentation of which states:
The calling process must have the
SE_BACKUP_NAME
privilege enabled. For more information, see Running with Special Privileges.
User tokens do not normally have the SE_BACKUP_NAME
privilege enabled. In order to meet this requirement you need to:
SE_BACKUP_NAME
privilege to your user token. The other requirement you must adhere to is that the output file must not exist before you call SaveKey
.
See this EDN article for C++ code illustrating the method.
Next variant worked!
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TRegistry *reg=new TRegistry(KEY_READ);
HANDLE ProcessToken;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &ProcessToken))
{
SetPrivilege(ProcessToken, SE_BACKUP_NAME, TRUE);
TRegistry *reg=new TRegistry(KEY_READ);
reg->RootKey=HKEY_LOCAL_MACHINE;
reg->SaveKey("Software","D:\\1.reg");
delete reg;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.