Results 1 to 3 of 3

Thread: [RESOLVED] RegRestoreKey fails on win7

  1. #1

    Thread Starter
    Member
    Join Date
    May 2009
    Location
    Victoria, BC
    Posts
    36

    Resolved [RESOLVED] RegRestoreKey fails on win7

    RegRestoreKey is failing with permissons in win7. All other versions of windows I have no problems running this code. I wrote the code like 5y ago. lol.

    From what I can find on the net, is that RegRestoreKey should request permission from UAC, and then continue. I never see the UAC popup, it just returns 1314 code.

    Here is my code, can anyone help me here?

    The Hive is current user.

    Code:
    Public Function ImportRegKey(ByVal eKeyRoot As EnumKeyRoot, ByVal sKeyPath As String, ByVal sFileName As String) As Boolean
        Dim hKey As Long
    
        If EnablePrivilege(SE_RESTORE_NAME) Then
            If RegOpenKeyEx(eKeyRoot, sKeyPath, 0&, KEY_ALL_ACCESS, hKey) = ERROR_SUCCESS Then
                ImportRegKey = (RegRestoreKey(hKey, sFileName, REG_FORCE_RESTORE) = ERROR_SUCCESS)
                RegCloseKey hKey
            End If
        End If
        
        If Not ImportRegKey Then
            MsgBox RegRestoreKey(hKey, sFileName, REG_FORCE_RESTORE)
            ' prints 1314
        End If
    End Function

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: RegRestoreKey fails on win7

    I don't know where you got the impression that using API functions that require permissions will automatically give a UAC prompt for you, but it isn't the case - you need to do it yourself.

    Looking at the documentation for RegRestoreKey: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
    ...it seems that a standard UAC elevation may not be enough, depending on the user rights:
    The calling process must have the SE_RESTORE_NAME and SE_BACKUP_NAME privileges
    I suspect it would be easier (and far more reliable) to do the work of RegRestoreKey yourself in stages using the other registry functions.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2009
    Location
    Victoria, BC
    Posts
    36

    Re: RegRestoreKey fails on win7

    Oops, I read the comment on another forum wrong. It does request it, but if it doesn't have permissions it fails.

    Looks like my only option is to use the other reg functions to write these keys.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width