如何用VB备份并恢复注册表色色了。。

解决方案 »

  1.   

    注册表是在用的系统文件,复制和替换都很难。
    不过可以试试用注册表的导出和导入功能。导出,只要读出相关的键和子键以及键值,按其导出文件的格式写入一个文本文件中,以 .reg 扩展名保存。
    导入,用 API函数 ShellExecute 执行 .reg 文件。另一个方法就是利用 VBA 脚本代码,下面是微软给的例子:
    ------------------------------------------------------------------------
    '
    ' This sample demonstrates how to write/delete entries in the registry. 
    L_Welcome_MsgBox_Message_Text   = "此脚本显示如何创建和删除注册表项。"
    L_Welcome_MsgBox_Title_Text     = "Windows Scripting Host 范例"
    Call Welcome()
    ' ********************************************************************************
    ' *
    ' * Registry related methods.
    ' *Dim WSHShell
    Set WSHShell = WScript.CreateObject("WScript.Shell")WSHShell.Popup "创建项 HKCU\MyRegKey 数值为 'Top level key'"
    WSHShell.RegWrite "HKCU\MyRegKey\", "Top level key"WSHShell.Popup "创建项 HKCU\MyRegKey\Entry 数值为 'Second level key'"
    WSHShell.RegWrite "HKCU\MyRegKey\Entry\", "Second level key"WSHShell.Popup "将数值项 HKCU\MyRegKey\Value 设为 REG_SZ 1"
    WSHShell.RegWrite "HKCU\MyRegKey\Value", 1WSHShell.Popup "将数值项 HKCU\MyRegKey\Entry 设为 REG_DWORD 2"
    WSHShell.RegWrite "HKCU\MyRegKey\Entry", 2, "REG_DWORD"WSHShell.Popup "将数值项 HKCU\MyRegKey\Entry\Value1 设为 REG_BINARY 3"
    WSHShell.RegWrite "HKCU\MyRegKey\Entry\Value1", 3, "REG_BINARY"WSHShell.Popup "删除 HKCU\MyRegKey\Entry\Value1 数值"
    WSHShell.RegDelete "HKCU\MyRegKey\Entry\Value1"WSHShell.Popup "删除 HKCU\MyRegKey\Entry 项"
    WSHShell.RegDelete "HKCU\MyRegKey\Entry\"WSHShell.Popup "删除 HKCU\MyRegKey 项"
    WSHShell.RegDelete "HKCU\MyRegKey\"'***********************************************************************
    Dim WshShell, bKey
    Set WshShell = WScript.CreateObject("WScript.Shell")WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"
    WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\MindReader", "Goocher!", "REG_SZ"bKey = WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\")
    WScript.Echo WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\MindReader")WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\MindReader"
    WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\"
    WshShell.RegDelete "HKCU\Software\ACME\"事先将注册表的内容读出,保存。然后利用创建、删除键以及写入键值来恢复注册表。
    需用注意的是,1 在 NT 架构的操作系统中,改写注册表主要相应的权限;2 有些键在更改后需要重新启动系统才会生效。