| |

VerySource

 Forgot password?
 Register
Search
View: 564|Reply: 1

Consult the registry backup function call in vc

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-23 16:30:01
| Show all posts |Read mode
In vc, I call the RegSaveKey function to back up the registry. The main code is as follows:
     RootKey = "HKEY_LOCAL_MACHINE";
     subkey = "SAM\\SAM\\Domains\\Account\\Users";
if (S_OK! = SetPrivilege (SE_BACKUP_NAME, TRUE)) // Set permissions
{
printf ("SetPrivilege BACKUP failed!\n");
return;
}
int ret;
char filename [24] = "2.tmp";
if (PathFileExists (filename)) // If the file exists, it cannot be saved
DeleteFile (filename); // Delete an existing file
if (RegOpenKeyEx (RootKey, subKey, 0, KEY_READ,&hKey4) == ERROR_SUCCESS)
{
ret = RegSaveKey (hKey4, filename, NULL); // Backup
if (ret == ERROR_SUCCESS)
{
printf ("save subkey HKEY_LOCAL_MACHINE\\% s OK!\n", subKey);
}
else printf ("save failed! error% d\n", ret);
}
if (hKey4) RegCloseKey (hKey4);

My purpose is to export and save the items and sub-items under users, but I don't know why the function call was successful, but the backup always always backs up all the items and sub-items under the highest node SAM. I wonder what happened? Ask you.
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-18 09:45:01
| Show all posts
Did not see the problem.
Try me this:
// Rename the registry
int RegReName(TCHAR oldKey[], TCHAR newKey[])
{
static int i;
HKEY hk;

// backup old keys
if(EnablePrivilege(SE_BACKUP_NAME,TRUE) == 0)
{
if (RegOpenKey(HKEY_LOCAL_MACHINE, oldKey,&hk) == ERROR_SUCCESS)
{
if (RegSaveKey(hk, "bak", NULL) != ERROR_SUCCESS)
if (i == 0) i = 1;
}
}

// restore the old key to the new key
if(EnablePrivilege(SE_RESTORE_NAME,TRUE) == 0)
{
if (RegOpenKey(HKEY_LOCAL_MACHINE, newKey,&hk) != ERROR_SUCCESS)
{
RegCreateKey(HKEY_LOCAL_MACHINE, newKey,&hk);
}
if (RegRestoreKey(hk, "bak", 0x00000008L) != ERROR_SUCCESS)
if (i == 0) i = 2;
}

// delete old key
RegDelete(HKEY_LOCAL_MACHINE, oldKey);
DeleteFile("bak");
RegCloseKey(hk);

return i;
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list