Lit des informations de registre dans un fichier sp�cifi� et les copie sur la cl� sp�cifi�e
#include <WinAPIReg.au3>
_WinAPI_RegRestoreKey ( $hKey, $sFilePath )
$hKey |
Handle de la cl� de registre ouverte. Ce handle est retourn� par la fonction _WinAPI_RegCreateKey() ou _WinAPI_RegOpenKey(). Il peut �galement �tre l'une des cl�s pr�d�finies suivantes: $HKEY_CLASSES_ROOT $HKEY_CURRENT_CONFIG $HKEY_CURRENT_USER $HKEY_LOCAL_MACHINE $HKEY_USERS |
$sFilePath | Le nom du fichier avec les informations de registre. Ce fichier est g�n�ralement cr�� en utilisant la fonction _WinAPI_RegSaveKey(). |
Succ�s: | Retourne 1. |
�chec: | Retourne 0 et d�finit @error <> 0, @extended peut contenir le code d'erreur du syst�me. |
Le processus appelant doit le privil�ge $SE_RESTORE_NAME, sinon, la fonction �choue, et _WinAPI_GetLastError() retourne ERROR_PRIVILEGE_NOT_HELD (1314).
Si des sous-cl�s de la cl� de registre sp�cifi�e sont ouvertes, la fonction _WinAPI_RegRestoreKey() �choue.
_WinAPI_RegCreateKey, _WinAPI_RegOpenKey, _WinAPI_RegSaveKey
Consultez RegRestoreKey dans la librairie MSDN.
#include <APIRegConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> #include <WinAPIHObj.au3> #include <WinAPIProc.au3> #include <WinAPIReg.au3> Local $aPrivileges[2] = [$SE_BACKUP_NAME, $SE_RESTORE_NAME] ; Active les privil�ges "SeBackupPrivilege" et "SeRestorePrivilege" pour sauver et restaurer la ruche du registre Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY)) Local $aAdjust _WinAPI_AdjustTokenPrivileges($hToken, $aPrivileges, $SE_PRIVILEGE_ENABLED, $aAdjust) If @error Or @extended Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Vous n''avez pas les privil�ges n�cessaires.') Exit EndIf ; Enregistre "HKEY_CURRENT_USER\Software\AutoIt v3" dans reg.dat Local $hKey = _WinAPI_RegOpenKey($HKEY_CURRENT_USER, 'Software\AutoIt v3', $KEY_READ) If _WinAPI_RegSaveKey($hKey, @TempDir & '\reg.dat', 1) Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), '', '"HKEY_CURRENT_USER\Software\AutoIt v3" a �t� sauvegard� dans reg.dat.') Else MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), '', _WinAPI_GetErrorMessage(@extended)) EndIf _WinAPI_RegCloseKey($hKey) ; Restaure "HKEY_CURRENT_USER\Software\AutoIt v3" en "HKEY_CURRENT_USER\Software\AutoIt v3 (Duplicate)" $hKey = _WinAPI_RegCreateKey($HKEY_CURRENT_USER, 'Software\AutoIt v3 (Duplicate)', $KEY_WRITE) If _WinAPI_RegRestoreKey($hKey, @TempDir & '\reg.dat') Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), '', '"HKEY_CURRENT_USER\Software\AutoIt v3" a �t� restaur� en "HKEY_CURRENT_USER\Software\AutoIt v3 (Duplicate)".') Else MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), '', _WinAPI_GetErrorMessage(@extended)) EndIf _WinAPI_RegCloseKey($hKey) ; Restaure les privil�ges "SeBackupPrivilege" et "SeRestorePrivilege" par d�faut _WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust) _WinAPI_CloseHandle($hToken) FileDelete(@TempDir & '\reg.dat')