Index: base/applications/regedit/framewnd.c =================================================================== --- base/applications/regedit/framewnd.c (révision 56819) +++ base/applications/regedit/framewnd.c (copie de travail) @@ -340,7 +340,19 @@ { if(DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOADHIVE), hWnd, &LoadHive_KeyNameInHookProc, (LPARAM)xPath)) { - LONG regLoadResult = RegLoadKey(hRootKey, xPath, ofn.lpstrFile); + LONG regLoadResult; + + /* Enable the required privileges */ + EnablePrivilege(SE_BACKUP_NAME, NULL, TRUE); + EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE); + + /* Load the hive */ + regLoadResult = RegLoadKey(hRootKey, xPath, ofn.lpstrFile); + + /* Disable the privileges */ + EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE); + EnablePrivilege(SE_BACKUP_NAME, NULL, FALSE); + if(regLoadResult == ERROR_SUCCESS) { /* refresh tree and list views */ @@ -373,8 +385,18 @@ pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); /* load and set the caption and flags for dialog */ LoadString(hInst, IDS_UNLOAD_HIVE, Caption, COUNT_OF(Caption)); - /* now unload the hive */ + + /* Enable the required privileges */ + EnablePrivilege(SE_BACKUP_NAME, NULL, TRUE); + EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE); + + /* Unload the hive */ regUnloadResult = RegUnLoadKey(hRootKey, pszKeyPath); + + /* Disable the privileges */ + EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE); + EnablePrivilege(SE_BACKUP_NAME, NULL, FALSE); + if(regUnloadResult == ERROR_SUCCESS) { /* refresh tree and list views */ Index: base/applications/regedit/main.h =================================================================== --- base/applications/regedit/main.h (révision 56819) +++ base/applications/regedit/main.h (copie de travail) @@ -139,6 +139,7 @@ /* security.c */ extern BOOL RegKeyEditPermissions(HWND hWndOwner, HKEY hKey, LPCTSTR lpMachine, LPCTSTR lpKeyName); +extern BOOL EnablePrivilege(LPCTSTR lpszPrivilegeName, LPCTSTR lpszSystemName, BOOL bEnablePrivilege); /* settings.c */ extern void LoadSettings(void); Index: base/applications/regedit/security.c =================================================================== --- base/applications/regedit/security.c (révision 56819) +++ base/applications/regedit/security.c (copie de travail) @@ -1022,4 +1022,35 @@ return Result; } +BOOL EnablePrivilege(LPCTSTR lpszPrivilegeName, + LPCTSTR lpszSystemName, + BOOL bEnablePrivilege) +{ + BOOL retVal = FALSE; + HANDLE hToken = NULL; + + if(OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES, + &hToken)) + { + TOKEN_PRIVILEGES tp; + tp.PrivilegeCount = 1; + + LookupPrivilegeValue(lpszSystemName, + lpszPrivilegeName, + &tp.Privileges[0].Luid); + tp.Privileges[0].Attributes = (bEnablePrivilege ? SE_PRIVILEGE_ENABLED : 0); + retVal = AdjustTokenPrivileges(hToken, + FALSE, + &tp, + sizeof(TOKEN_PRIVILEGES), + NULL, + NULL); + + CloseHandle(hToken); + } + + return retVal; +} + /* EOF */