Skip to main content

[archive] Renaming a key in Windows Registry

  • June 11, 2008
  • 1 reply
  • 0 views

[Migrated content. Thread originally posted on 10 June 2008]

I am trying to rename a subkey in the windows registry and it appears as though there is not a way to do this with a simple command. From a lot of the searching I've done, it seems like I must create new entries for each of the values underneath my subkey and then delete the original. Is this true? Does anyone have a sample program in COBOL that does this?

For example, I want to rename the following key:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Robstan

to:

HKEY_LOCAL-MACHINE\\SOFTWARE\\NewRobstan

There are several subkeys and values underneath Robstan. I'd love to hear some suggestions on this one. Thanks in advance!

Rob

1 reply

[Migrated content. Thread originally posted on 10 June 2008]

I am trying to rename a subkey in the windows registry and it appears as though there is not a way to do this with a simple command. From a lot of the searching I've done, it seems like I must create new entries for each of the values underneath my subkey and then delete the original. Is this true? Does anyone have a sample program in COBOL that does this?

For example, I want to rename the following key:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Robstan

to:

HKEY_LOCAL-MACHINE\\SOFTWARE\\NewRobstan

There are several subkeys and values underneath Robstan. I'd love to hear some suggestions on this one. Thanks in advance!

Rob
There is no "rename" functionality in the Windows API on the registry, so your best bet is to delete the key and create it over again. This is actually deliberate from Microsoft. The more modifications that are done to the keys, the more fragmented the registry will become and thus impact performance.
The API does however have a somewhat related mechanism, RegReplaceKey, this will allow you to replace a key and its hive in that it will create a new registry which will be loaded next time the OS is started (This is one of the reasons installing new software will tell you to reboot...). This function is however not available from the ACUCOBOL-GT library functions.