Does anyone know how to rename a registry key using API's?
:)
Printable View
Does anyone know how to rename a registry key using API's?
:)
Unfortunately, this is harder than it looks :rolleyes:
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. :eek:
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. :eek:
You'll get over it :rolleyes:
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). :rolleyes:
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.
:)
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 :rolleyes:
VB Code:
Option Explicit 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 Private Declare Function SHDeleteKey Lib "shlwapi" Alias "SHDeleteKeyA" (ByVal hkey As Long, ByVal pszSubKey As String) As Long
Thanks again for all your help Yonatan and crispin.
:D :D :D :D :D :D :D :D :D
Why wouldn't you want the Unicode version? It's better to use the Unicode version if your program is run on NT.
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 :rolleyes:
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.