以标准格式保存指定键及其子项和值到新文件.
#Include <WinAPIEx.au3>
_WinAPI_RegSaveKey ( $hKey, $sFile [, $tSecurity] )
$hKey | 注册表项句柄. |
$sFile | 文件的名称. 如果该文件已经存在,函数替换它.新文件具有存档属性. |
$tSecurity | [可选参数] $tagSECURITY_ATTRIBUTES 结构, 指定新文件的安全描述符.如果此参数为 0,该文件使用默认的安全描述符. |
成功: | 返回 1. |
失败: | 返回 0,设置 @error 标志为非 0 值, @extended 标志可能包含系统错误代码. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $aPrivileges[2] = [$SE_BACKUP_NAME, $SE_RESTORE_NAME]
Global $aAdjust, $hToken, $hKey
; Enable "SeBackupPrivilege" and "SeRestorePrivilege" privileges to save and restore registry hive
$hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
_WinAPI_AdjustTokenPrivileges($hToken, $aPrivileges, $SE_PRIVILEGE_ENABLED, $aAdjust)
If @error Or @extended Then
MsgBox(16, 'Error', 'You do not have the required privileges.')
Exit
EndIf
; 保存 "HKEY_CURRENT_USER\Software\AutoIt v3" 到 reg.dat
$hKey = _WinAPI_RegOpenKey($HKEY_CURRENT_USER, 'Software\AutoIt v3', $KEY_READ)
If _WinAPI_RegSaveKey($hKey, @ScriptDir & '\reg.dat', 1) Then
MsgBox(64, '', '"HKEY_CURRENT_USER\Software\AutoIt v3" has been saved to reg.dat.')
Else
MsgBox(16, '', _WinAPI_GetErrorMessage(@extended))
EndIf
_WinAPI_RegCloseKey($hKey)
; 还原 "HKEY_CURRENT_USER\Software\AutoIt v3" 到 "HKEY_CURRENT_USER\Software\AutoIt v3 (副本)"
$hKey = _WinAPI_RegCreateKey($HKEY_CURRENT_USER, 'Software\AutoIt v3 (Duplicate)', $KEY_WRITE)
If _WinAPI_RegRestoreKey($hKey, @ScriptDir & '\reg.dat') Then
MsgBox(64, '', '"HKEY_CURRENT_USER\Software\AutoIt v3" has been restored to "HKEY_CURRENT_USER\Software\AutoIt v3 (Duplicate)".')
Else
MsgBox(16, '', _WinAPI_GetErrorMessage(@extended))
EndIf
_WinAPI_RegCloseKey($hKey)
; Restore "SeBackupPrivilege" and "SeRestorePrivilege" privileges by default
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)
FileDelete(@ScriptDir & '\reg.dat')