热情软件屋

 

如何输出注册表内容到.reg文件


编号:QA001567
建立日期: 1999年8月22日 最后修改日期:2003年1月5日
所属类别:

Cai Xuan:
    Win98
    VB
    怎样用VB备份注册表。不是整个备份,而是备份注册表下面的分支,想生成一个.reg文件,好象有个现在的API可用,但生成的是二进制文件。

回答:

    其实只要用Shell执行regedit /e就可以了。用法是:
     regedit /e <备份文件名(.reg)> <注册表键名>
    需要注意的是在Shell命令中加双引号的方法。
    
    操作系统: win2000
    编程工具: dephi5
    问题: 我想编写这样的程序,程序在运行时可对注册表中的子键进行保存恢复修改功能(如同用regedit.exe 命令的导入导出功能)。我曾使用下述调用外部命令的方法,结果不能实现:
     1) shellexecute(0,'open','regedit.exe/e Backup.reg',nil,nil,sw_normal);
     我又采用调用WINDOWS API 函数 ,RegSaveKey,RegLoadKey,结果也不能实现.
     我调用的demo如下:
    
    unit regsavek;
    interface
    uses
     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
    type
     TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
     private
     { Private declarations }
     public
     { Public declarations }
     end;
    var
     Form1: TForm1;
    implementation
    
    {$R *.DFM}
    procedure TForm1.FormCreate(Sender: TObject);
    var
     phKey: hKey;
     FileName: array[0..255] of char;
     KeyName: string;
     InputName: string;
    begin
     phKey :=HKEY_LOCAL_MACHINE;
     InputName := InputBox('Enter file name','Enter a filename without extension.','');
     StrPCopy(FileName,InputName);
     if RegSaveKey(phKey, FileName, nil)=0 then
     ShowMessage('Key information exported.')
     else
     ShowMessage('Key information not exported.');
     RegCloseKey(phKey);
    end;
    
    end.
    

    结果运行总是出现Key information not exported.
    请问:我要怎样才能实现对注册表的操作(运行态下)。谢谢!
    水平: 刚入门
    *********** WinExec('RegEdit.exe /e Backup.reg HKEY_LOCAL_MACHINE', SW_HIDE)命令已试通 **************
    ????
    李海答:如果使用ShellExecute,需要注意它命令行是在第3个参数,而不是第2个参数,如:
    ShellExecute(0, 'open', 'regedit.exe', '/e Backup.reg HKEY_LOCAL_MACHINE', nil, sw_normal);

此问题由Prisoner回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio