none
那么多的注册表API函数中,真的就没有regRenameKey()??? RRS feed

  • 问题

  • Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias
    "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
    As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias
    "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As
    Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
    (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias
    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal
    ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

    Private Const HKEY_LOCAL_MACHINE = &H80000002

    Private Const STANDARD_RIGHTS_ALL = &H1F0000
    Private Const KEY_QUERY_VALUE = &H1
    Private Const KEY_SET_VALUE = &H2
    Private Const KEY_CREATE_SUB_KEY = &H4
    Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    Private Const KEY_NOTIFY = &H10
    Private Const KEY_CREATE_LINK = &H20
    Private Const SYNCHRONIZE = &H100000
    Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or
    KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
    Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

    Public Function regRenameKey(ByVal hKey As Long, lpSubKey As String,
    lpNewSubKey As String) As Long
    Dim lRet As Long
    Dim lKey As Long

    'lRet = RegOpenKey(hKey, lpSubKey, lKey) '起初以为是权限的问题
    lRet = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_ALL_ACCESS, lKey)
    lRet = RegDeleteKey(hKey, lpSubKey)
    Debug.Print "lRet=" & lRet ‘总是返回lRet=5的错误

    lRet = RegCreateKey(hKey, lpNewSubKey, lKey)

    lRet = RegCloseKey(lKey)
    regRenameKey = lRet
    End Function
    那么多的注册表API函数中,真的就没有regRenameKey()??? 

     

    2007年8月2日 7:09

答案

  • Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias
    "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
    As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias
    "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As
    Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
    (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias
    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal
    ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

    Private Const HKEY_LOCAL_MACHINE = &H80000002

    Private Const STANDARD_RIGHTS_ALL = &H1F0000
    Private Const KEY_QUERY_VALUE = &H1
    Private Const KEY_SET_VALUE = &H2
    Private Const KEY_CREATE_SUB_KEY = &H4
    Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    Private Const KEY_NOTIFY = &H10
    Private Const KEY_CREATE_LINK = &H20
    Private Const SYNCHRONIZE = &H100000
    Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or
    KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
    Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

    Public Function regRenameKey(ByVal hKey As Long, lpSubKey As String,
    lpNewSubKey As String) As Long
    Dim lRet As Long
    Dim lKey As Long

    'lRet = RegOpenKey(hKey, lpSubKey, lKey) '起初以为是权限的问题
    lRet = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_ALL_ACCESS, lKey)
    lRet = RegDeleteKey(hKey, lpSubKey)
    Debug.Print "lRet=" & lRet ‘总是返回lRet=5的错误

    lRet = RegCreateKey(hKey, lpNewSubKey, lKey)

    lRet = RegCloseKey(lKey)
    regRenameKey = lRet
    End Function
    那么多的注册表API函数中,真的就没有regRenameKey()???

     

    2007年8月2日 8:42