如何导出注册表(新安装程序的注册项目)?(50分)

  • 主题发起人 主题发起人 zhongwanglong
  • 开始时间 开始时间
Z

zhongwanglong

Unregistered / Unconfirmed
GUEST, unregistred user!
如何导出注册表(新安装程序的注册项目)?
 
1.调用regedit uses shellapi
shellexecute(handle,'open','regedit.exe',' /e YourWantExportKey YourBackUpFilename','',sw_hide)

2.用windoews API函数RegSaveKey或RegRestoreKey

The RegSaveKey function saves the specified key and all of its subkeys
and values to a new file.

LONG RegSaveKey(
HKEY hKey, // handle of key where save begins
LPCTSTR lpFile, // address of filename to save to
LPSECURITY_ATTRIBUTES lpSecurityAttributes // address of security structure
);

The RegRestoreKey function reads the registry information in a specified file
and copies it over the specified key. This registry information may be in the
form of a key and multiple levels of subkeys.

LONG RegRestoreKey(
HKEY hKey, // handle of key where restore begins
LPCTSTR lpFile, // address of filename containing saved tree
DWORD dwFlags // optional flags
);

下面是代码
procedure TFormMain.ButtonExportClick(Sender: TObject);
var
RootKey,phKey: hKey;
KeyName,sKeyFileName: String;
FileName: array [0..255] of char;
begin
RootKey := HKEY_CURRENT_USER;
KeyName := 'software/mysoft/abc';
RegOpenKeyEx(RootKey, PChar(KeyName), 0, KEY_ALL_ACCESS, phKey);
sKeyFileName := 'c:/tempReg';
StrPCopy(FileName,sKeyFileName); //用pchar也行
if RegSaveKey(phKey, FileName, nil)= 0 then
ShowMessage('注册表分支已被导出。')
else
ShowMessage('注册表分支没有被导出。');
RegCloseKey(phKey);
end;

procedure TFormMain.ButtonImportClick(Sender: TObject);
var //从文件导回到注册表
RootKey,phKey: hKey;
KeyName,sKeyFileName: String;
FileName: array [0..255] of char;
begin
RootKey := HKEY_CURRENT_USER;
KeyName := 'software/mySoft/abc';
RegOpenKeyEx(RootKey, PChar(KeyName), 0, KEY_ALL_ACCESS, phKey);
sKeyFileName := 'c:/tempReg';
StrPCopy(FileName,sKeyFileName);
if RegRestoreKey(phKey, FileName,0)= 0 then
ShowMessage('注册表指定分支已恢复。')
else
ShowMessage('注册表指定分支没有恢复,操作失败。');
RegCloseKey(phKey);
end;


3.另外, 还可以用TRegistry的savekey和restorekey
var
reg : Tregistry;
begin
reg := Tregistry.Create;
reg.rootkey := HKEY_CURRENT_USER;
reg.Savekey('/Software/NetAnts','d:/test1/NetAnts');
end;

 
reg_binary,但怎么用(具体点)
如要写入 二进制的 08 02 04 E5
如何用 writebinary操作?
 
接受答案了.
 
后退
顶部