Windows CE: Save and Restore the Registry
来源:互联网 发布:淘宝客哪里设置 编辑:程序博客网 时间:2024/05/01 22:42
In other posts, I have discussed persistent registry (Windows CE: Persisting Registry Changes from an Application) but what if we want to set the registry back to some known point? There are some functions to save the registry, or parts of the registry, and the restore them later.
Save and Restore the Entire Registry
The functions RegCopyFile() and RegRestoreFile() can be used to save the registry to a file and then restore the registry with that file later. The following are two very simple applications to that use these functions to save and restore the registry.
SaveReg simply saves the registry to a file on a Storage Card. The saved registry is a binary file, so not a .REG file. I used the extension SRG for Saved ReGistry.
#include <Windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
RegCopyFile( TEXT("//Storage Card//SaveReg.srg") );
}
Then to restore the registry with the file I created RestoreReg. RestoreReg calls RegRestoreFile() which sets up the system to restore the registry after a soft reset, then uses KernelIoControl to perform the soft reset (For more see Windows CE: Soft Reset.)
#include <Windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
RegRestoreFile( TEXT("//Storage Card//SaveReg.srg") );
KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
When the system restarts the registry will be replaced with the registry from the saved file.
Save and Restore Root Keys
The functions RegSaveKey() and RegReplaceKey() can be used with hive based registry only. These functions can save and restore the root keys; HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT and HKEY_USER. The documentation for these functions is a little vague and the function signatures are deceiving so you will see that I have added some basic error handling.
In this instance of SaveReg, the app saves the root key HKEY_LOCAL_MACHINE:
#include <Windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if( ERROR_SUCCESS != RegSaveKey( HKEY_LOCAL_MACHINE, TEXT("//Storage Card//SaveReg.srg"), NULL ))
RETAILMSG( 1, (TEXT("RegSaveKey failed (%d)/n"), GetLastError() ));
}
I had to add the error handling because the file is created as a System Hidden file. So at first it looked like the function had failed, then it actually did fail because the file already existed from the first time that I ran the application. RegSaveFile does not save the file as System or Hidden.
In this instance of RestoreReg, the app restores HKEY_LOCAL_MACHINE.
#include <Windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if( ERROR_SUCCESS != RegReplaceKey( HKEY_LOCAL_MACHINE, NULL, TEXT("//Storage Card//SaveReg.srg"), NULL ))
RETAILMSG( 1, (TEXT("RegReplaceKey failed (%d)/n"), GetLastError() ));
else
{
KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
}
For this application, I need to add the error handling because my first attempt included a subkey string, which is not valid.
So now we have two ways to save and restore the registry to a know version.
- Windows CE: Save and Restore the Registry
- canvas save and restore
- Windows CE Registry
- Understanding save() and restore() for the Canvas Context
- vim save and restore session
- [CE编程]第7章 Files, Databases, and the Registry (二)CE中的数据库API
- SPOT the Geek and Windows CE Drivers
- How to use the System Restore API to save and to restore system data in Visual C++
- The Real Best Practices to Save/Restore Activity's and Fragment's state.
- [CE编程]第7章 Files, Databases, and the Registry (-)文件系统
- experiment: save and restore file time
- OMAP4430 SAR RAM(Save And Restore)
- Services.exe and the Windows CE 6.0 kernel (FROM FEEDSFARM)
- Windows CE and Andriod
- A quick complete tutorial to save and restore Tensorflow models
- Tensorflow: 保存和复原模型(save and restore)
- A quick complete tutorial to save and restore Tensorflow models
- Tensorflow: 保存和复原模型(save and restore)
- 最近接触到的一些技术
- ASP.NET生成随机密码
- __doPostBack()无效 ?
- 使用Telnet进行SMTP/POP3/FTP/NNTP
- 解读奇怪却合理的IT人才格局
- Windows CE: Save and Restore the Registry
- C#时间间隔计算可以通过时间刻度类TimSpan类
- 19-Nov-2009
- ASP.NET中防止页面多次提交的代码实现
- SMTPDiag 诊断工具
- Java NIO类库Selector机制解析
- jquery实现ajax跨域访问
- 装SQL2005注意
- 白名单(Whitelisting) 技术