Discussion:
How to rename a registry key using vbscript?
(too old to reply)
Matthew Bell
2008-10-17 13:36:11 UTC
Permalink
I've searched the Internet, and have learned there's no native,
single-command way to do this within vbscript. Someone out there made
reference to the possibility of it being done via a vbs script that (I'm
surmising) enumerates all keys and values recursively, and writes what it
finds to a new (and newly-named) key, then deletes the old (formerly-named)
key.

Can anyone point me to such a vbs script out there, or spell out for me what
the logic of the code would be for this type of recursion through registry
keys & values? Thanks.
mr_unreliable
2008-10-17 17:42:28 UTC
Permalink
hi Matthew,

I don't have any scripting examples for you, but in
general there are two ways to go.

Way 1: you can use the "native" scripting methods,
regread/regwrite/regdelete to do what you want.

Way 2: there are wmi class(es) you can use, such as
win32_registry, and win32_registryaction.

You can find example code for using both of these
approaches by searching this ng.

http://groups.google.com/advanced_search

Whichever method you use, your script will be complicated
depending on how complicated the registry entry(ies) you are
concerned about is(are). For example, how many subkeys.
The general consensus opinion found here is that for
complicated enumerations, the wmi approach works better.

And yes, afaik there is no handy method for changing the
registry entries "in place". If I am correct about this,
you will have to write out the registry entries (to text)
delete the existing entries, modify the registry text,
and them write them back into registry.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
Post by Matthew Bell
I've searched the Internet, and have learned there's no native,
single-command way to do this within vbscript. Someone out there made
reference to the possibility of it being done via a vbs script that (I'm
surmising) enumerates all keys and values recursively, and writes what it
finds to a new (and newly-named) key, then deletes the old (formerly-named)
key.
Can anyone point me to such a vbs script out there, or spell out for me what
the logic of the code would be for this type of recursion through registry
keys & values? Thanks.
Salvador Manaois III
2008-10-17 23:48:06 UTC
Permalink
Here's a very simple example:

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oRegistry=GetObject("winmgmts:\\" & strComputer _
& "\root\default:StdRegProv")
sKeyPath = "Software\Badz"
sValueName = "Salvador Manaois III"
oRegistry.DeleteValue HKEY_CURRENT_USER, strKeyPath, strValueName

Things get a tad complicated if you need to enumerate keys and values from
the registry and incorporate your logic therein (say, rename "Testing" key to
"TestDone" or set a value for a string (REG_SZ) "Description", etc). You can
use the usual registry enumeration methods, enumkeys or enumvalues (of the
StdRegProv Class) to list keys/values:

http://msdn.microsoft.com/en-us/library/aa390387(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa390388(VS.85).aspx

Then you can make use of regread, regwrite or regdelete to perform the
needed action:

http://msdn.microsoft.com/en-us/library/2x3w20xf(VS.85).aspx
--
Salvador Manaois III
MCSE MCSA CEH MCITP | Enterprise/Server Admin
Bytes & Badz : http://badzmanaois.blogspot.com
Post by Matthew Bell
I've searched the Internet, and have learned there's no native,
single-command way to do this within vbscript. Someone out there made
reference to the possibility of it being done via a vbs script that (I'm
surmising) enumerates all keys and values recursively, and writes what it
finds to a new (and newly-named) key, then deletes the old (formerly-named)
key.
Can anyone point me to such a vbs script out there, or spell out for me what
the logic of the code would be for this type of recursion through registry
keys & values? Thanks.
Continue reading on narkive:
Loading...