c++备份与恢复注册表-错误记录
来源:互联网 发布:二叉树的遍历算法c 编辑:程序博客网 时间:2024/06/02 04:34
在学习用c++进行注册表备份与恢复时。
参考网上资料进行学习。
http://www.cnblogs.com/john-h/p/5886870.html
备份与恢复均要申请权限。
void RegistryFunctionLib_class::Get_SE_BACKUP_NAME_Power(){HANDLE hToken = NULL;LUID sedebugnameValue;TOKEN_PRIVILEGES tkp;if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)){ //error}if (!LookupPrivilegeValue(NULL, SE_BACKUP_NAME, &sedebugnameValue)){//error}tkp.PrivilegeCount = 1;tkp.Privileges[0].Luid = sedebugnameValue;tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL)){//error}CloseHandle(hToken);}以管理员权限运行程序后备份成功,而在进行恢复时却始终不成功。
于是去msdn官网查询函数RegRestoreKey,发现标识位并非是true或false。
_In_ DWORD dwFlags
- dwFlags [in]
The flags that indicate how the key or keys are to be restored. This parameter can be one of the following values.
Value Meaning - REG_FORCE_RESTORE
- 0x00000008L
If specified, the restore operation is executed even if open handles exist at or beneath the location in the registry hierarchy to which thehKey parameter points.
- REG_WHOLE_HIVE_VOLATILE
- 0x00000001L
If specified, a new, volatile (memory only) set of registry information, or hive, is created. If REG_WHOLE_HIVE_VOLATILE is specified, the key identified by thehKey parameter must be either theHKEY_USERS orHKEY_LOCAL_MACHINE value.
REG_FORCE_RESTORE=永久恢复,REG_WHOLE_HIVE_VOLATILE=临时恢复。
设置后依旧不成功,阅读msdn文档介绍发现,进行恢复时需要将SE_BACKUP_NAME替换为SE_RESTORE_NAME,在
if (!LookupPrivilegeValue(NULL, SE_BACKUP_NAME,&sedebugnameValue))中
The calling process must have the SE_RESTORE_NAME and SE_BACKUP_NAME privileges on the computer in which the registry resides. For more information, see Running with Special Privileges.
附上msdn链接https://msdn.microsoft.com/en-us/library/windows/desktop/ms724915(v=vs.85).aspx
- c++备份与恢复注册表-错误记录
- 问题:必须使用记录或另一备份以恢复包含系统注册表
- 记录一次 MySQL 逻辑备份与恢复的演练
- Windows 2000 的注册表备份和恢复
- 注册表的备份和恢复方法
- Windows CE下注册表备份和恢复
- Windows CE下注册表备份和恢复
- ORACLE备份恢复杂谈记录
- mysql备份错误记录
- 备份与恢复 FAQ
- 备份与恢复
- MySQL备份与恢复
- sql2000备份与恢复
- Oracle 备份与恢复
- 数据库备份与恢复
- Oracle 备份与恢复
- Mysql 备份与恢复
- 数据库备份与恢复
- 函数模板与类模板
- linux上安装memcached步骤
- 为什么占位符,可以防止sql注入漏洞?
- 搜索引擎选择: Elasticsearch与Solr
- python 接收反弹shell
- c++备份与恢复注册表-错误记录
- Logistic回归损失函数证明
- 34:回文子串
- 将博客搬至CSDN
- 怎么理解物理像素和CSS像素?
- #Deep Learning回顾#之LeNet、AlexNet、GoogLeNet、VGG、ResNet
- MySQL系列—全文检索(fulltext)介绍
- ssm
- 洛谷Oj-垃圾陷阱-背包