Results 1 to 10 of 10

Thread: Registry (This is one for the Guru's)

  1. #1

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Registry (This is one for the Guru's)

    Does anyone know how to rename a registry key using API's?

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Unfortunately, this is harder than it looks
    I can think of two solutions:

    First Solution I Could Think Of
    Use RegEnumKeyEx and RegEnumValue to enumerate all the subkeys and values. Then, delete the key using RegDeleteKey. Finally, use RegCreateKeyEx to recreate the key with another name, and RegSetValueEx to set all the values back where they were.

    Second Solution I Could Think Of
    Use GetTempPath and GetTempFileName to get a temporary file name. Then, use RegSaveKey to save your key and all its subkeys in the temporary file. Delete the key from the registry using RegDeleteKey. Load the temporary file into a string buffer, and use the Replace function to replaces all instances of "OldKeyName" with "NewKeyName", and save the result back into the temporary file. Then, call RegRestoreKey to load the temporary file back into the registry, and finally, delete the temporary file.

    You'll get over it

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    The only problem with SHCopyKey is that your users will have to have Windows 98/2000, or have Internet Explorer 5.0 installed (or both).
    If you don't care about this limitation, enjoy, and use SHDeleteKey to easily delete the keys, too
    Note: SHDeleteKey is a bit less limited, your users will have to have Windows 98/2000, or have Internet Explorer 4.0 installed (or both).

  4. #4

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    I've just search the Web, looking for the SHCopyKey declare statement and I can't find it anywhere.

    Has anyone got any details on how to declare the SHCopyKey and SHDeleteKey API's, and how to use them.

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    First, you can't ignore the "Reserved" parameter in SHCopyKey.
    Second, these function have an ANSI version (which you want) and a Unicode version (which you don't want), so you should add an Alias to the ANSI version.
    Oh well
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SHCopyKey Lib "shlwapi" Alias "SHCopyKeyA" (ByVal hkeySrc As Long, ByVal szSrcSubKey As String, ByVal hkeyDest As Long, ByVal fReserved As Long) As Long
    4. Private Declare Function SHDeleteKey Lib "shlwapi" Alias "SHDeleteKeyA" (ByVal hkey As Long, ByVal pszSubKey As String) As Long

  6. #6

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Talking

    Thanks again for all your help Yonatan and crispin.


  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Why wouldn't you want the Unicode version? It's better to use the Unicode version if your program is run on NT.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Because the Unicode version of the function is not even implemented on Win9x, so if you use the Unicode version then your app would be limited to WinNT only.
    It'll get over it

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I didn't mean *just* Unicode...it's better practice to call the Unicode versions if you're running on NT because it saves an extra thunk call.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

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