Renaming Directories in the Registry

  • Thread starter Thread starter Lawrence Lu
  • Start date Start date
L

Lawrence Lu

How would I rename a directory in the Registry using the
command line or a .bat file? I am trying to find a way
to automate the renaming of several directories in the
Registry WITHOUT using VB.

Thanks.

Lawrence Lu
 
Did you mean keys and not directories? You'll need to construct your *.reg
file such that you create the new key (and values) while deleting the old
key (and values)
 
No, I meant directories =). The program I am writing
needs to rename several directories in the Windows
Registry.

If this isn't possible, then for my workaround I would
build a .reg file that does it the hard way. Is there a
way to delete an entire tree in the registry? (assuming
enough permissions)

Thanks

-----Original Message-----
Did you mean keys and not directories? You'll need to construct your *.reg
file such that you create the new key (and values) while deleting the old
key (and values)

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]

Lawrence Lu said:
How would I rename a directory in the Registry using the
command line or a .bat file? I am trying to find a way
to automate the renaming of several directories in the
Registry WITHOUT using VB.

Thanks.

Lawrence Lu


.
 
There are no directories in the registry. Only keys and values or various
data types. You say you're writing a program, without VB. So one can only
guess at this point.

reg.exe, VBScript are a couple that come to mind.
 
Lawrence Lu wrote in
No, I meant directories =). The program I am writing
needs to rename several directories in the Windows
Registry.

If this isn't possible, then for my workaround I would
build a .reg file that does it the hard way. Is there a
way to delete an entire tree in the registry? (assuming
enough permissions)

Possible confusion over terminology. Within the Windows registry are
KEYS and inside keys may be sub-KEYS, and data. The "name" of a
datastore is the VALUENAME (or just name) and the stored data is the
DATA. The data may be stored in several forms such as String
(REG_SZ) and others and that is known as the TYPE. (eg DWORD type).

"Directories" are not part of the structure of the registry.
Although a fully qualified path to a disk directory might be DATA
within the registry.

So, if you can ask again explaining in the accepted terms what it is
you are trying to accomplish...

-----Original Message-----
Did you mean keys and not directories? You'll need to construct your *.reg
file such that you create the new key (and values) while deleting the old
key (and values)

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]

Lawrence Lu said:
How would I rename a directory in the Registry using the
command line or a .bat file? I am trying to find a way
to automate the renaming of several directories in the
Registry WITHOUT using VB.

Thanks.

Lawrence Lu


.
 
Ok, sorry for the confusion. Let me give you an example
of what I'm trying to do. In the Windows Registry (as
seen from regedit.exe) there is a tree. Lets say there
is a tree "HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM". What
your saying is that this "tree" is a key? Anyways, what
I would like to do is change the tree's "name" to:
HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM2 . I called them
directories because thats what it looked like in
regedit.exe .

I tried doing this:

[HKEY_LOCAL_MACHINE\SOFTWARE\]
"MYPROGRAM"="MYPROGRAM2"

But that added a key to the \Software\ tree.

Thanks
-----Original Message-----
Lawrence Lu wrote in news:49b501c37626$9b142790 [email protected]:
No, I meant directories =). The program I am writing
needs to rename several directories in the Windows
Registry.

If this isn't possible, then for my workaround I would
build a .reg file that does it the hard way. Is there a
way to delete an entire tree in the registry? (assuming
enough permissions)

Possible confusion over terminology. Within the Windows registry are
KEYS and inside keys may be sub-KEYS, and data. The "name" of a
datastore is the VALUENAME (or just name) and the stored data is the
DATA. The data may be stored in several forms such as String
(REG_SZ) and others and that is known as the TYPE. (eg DWORD type).

"Directories" are not part of the structure of the registry.
Although a fully qualified path to a disk directory might be DATA
within the registry.

So, if you can ask again explaining in the accepted terms what it is
you are trying to accomplish...

-----Original Message-----
Did you mean keys and not directories? You'll need to construct your *.reg
file such that you create the new key (and values)
while
deleting the old
key (and values)

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]

:
How would I rename a directory in the Registry using the
command line or a .bat file? I am trying to find a way
to automate the renaming of several directories in the
Registry WITHOUT using VB.

Thanks.

Lawrence Lu


.

.
 
So you're halfway there. Now all you need to do is delete the old key

If you want to remove a key and all it's underlying values then you'll need
to construct your .reg file with a - minus sign in front of the key you want
to remove.

An example file to remove a file association .zzz from HKCR
-----------------Begin File-----------
Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\.zzz]
----------------End File-------------

(note the minus sign in front of HKEY)


If you need to delete only certain values, for example the string value
"InfoTip"="Contains zzz files"

Then put a minus sign after the equals sign without "quotes", something like
"InfoTip"=-

So your .reg file would look like
----------------Begin File------------
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.zzz]
"InfoTip"=-
----------------End File-------------

regedit /s filename.reg to import silently
 
Ok thanks, that will be helpful, but that doesn't really
solve the initial problem. Let me see if I can describe
it better.

Open regedit, then go to a tree, lets
say "HKEY_LOCAL_MACHINE\SOFTWARE". Then right click on
this "folder" (it looks like a folder!) and then select
Rename, then rename it to something else. This is what I
am trying to do. From what you said in your previous
post is that everything in the registry is a key, but
where do these "directories" (i dont know what else to
call them) exist so i can change them?

Like I said in my previous post, when I tried:
[HKEY_LOCAL_MACHINE\SOFTWARE\]
"MYPROGRAM"="MYPROGRAM2"

It didn't actually RENAME the tree to the new name. The
tree HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM was untouched,
and instead there was a key in
HKEY_LOCAL_MACHINE\SOFTWARE\ which was MYPROGRAM =
MYPROGRAM2.

Is this making sense? If it would be easier to discuss
over email, please email me. Thanks!


-----Original Message-----
So you're halfway there. Now all you need to do is delete the old key

If you want to remove a key and all it's underlying values then you'll need
to construct your .reg file with a - minus sign in front of the key you want
to remove.

An example file to remove a file association .zzz from HKCR
-----------------Begin File-----------
Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\.zzz]
----------------End File-------------

(note the minus sign in front of HKEY)


If you need to delete only certain values, for example the string value
"InfoTip"="Contains zzz files"

Then put a minus sign after the equals sign
without "quotes", something like
"InfoTip"=-

So your .reg file would look like
----------------Begin File------------
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.zzz]
"InfoTip"=-
----------------End File-------------

regedit /s filename.reg to import silently

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]

Lawrence Lu said:
Ok, sorry for the confusion. Let me give you an example
of what I'm trying to do. In the Windows Registry (as
seen from regedit.exe) there is a tree. Lets say there
is a tree "HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM". What
your saying is that this "tree" is a key? Anyways, what
I would like to do is change the tree's "name" to:
HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM2 . I called them
directories because thats what it looked like in
regedit.exe .

I tried doing this:

[HKEY_LOCAL_MACHINE\SOFTWARE\]
"MYPROGRAM"="MYPROGRAM2"

But that added a key to the \Software\ tree.

Thanks


.
 
Use reg.exe from the Windows 2000 Support Tools, located on the Windows 2000
operating system CD-ROM in the \support directory. The Support Tools must be
installed separately from the Windows 2000 operating system

D:\>reg copy /?

Console Registry Tool for Windows - version 3.0
Copyright (C) Microsoft Corp. 1981-2001. All rights reserved


REG COPY KeyName1 KeyName2 [/s] [/f]

KeyName [\\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the current
machine
Only HKLM and HKU are available on remote machines
FullKey ROOTKEY\SubKey
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY
/s Copies all subkeys and values
/f Forces the copy without propmt

Examples:

REG COPY HKLM\Software\MyCo\MyApp HKLM\Software\MyCo\SaveMyApp /s
Copies all subkeys and values under the key MyApp to the key SaveMyApp

REG COPY \\ZODIAC\HKLM\Software\MyCo HKLM\Software\MyCo1
Copies all values under the key MyCo on ZODIAC to the key MyCo1
on the current machine
 
Lawrence Lu wrote in
Ok thanks, that will be helpful, but that doesn't really
solve the initial problem. Let me see if I can describe
it better.

Open regedit, then go to a tree, lets
say "HKEY_LOCAL_MACHINE\SOFTWARE". Then right click on
this "folder" (it looks like a folder!) and then select
Rename, then rename it to something else. This is what I
am trying to do.

That "rename" operation is a function of the GUI regedit.exe. There
is no rename capability when using .REG files.
It looks like you are on to reg.exe and the copy-to-a-new-keyname,
then delete the old key method. That should work for you I think.

It is also possible to do this by way of .reg files, but it is not a
"rename" per se.

Always backup the entire registry beforehand for safety and recovery
in case things go wrong.

From what you said in your previous
post is that everything in the registry is a key, but
where do these "directories" (i dont know what else to
call them) exist so i can change them?

Like I said in my previous post, when I tried:
[HKEY_LOCAL_MACHINE\SOFTWARE\]
"MYPROGRAM"="MYPROGRAM2"

It didn't actually RENAME the tree to the new name. The
tree HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM was untouched,
and instead there was a key in
HKEY_LOCAL_MACHINE\SOFTWARE\ which was MYPROGRAM =
MYPROGRAM2.

Is this making sense? If it would be easier to discuss
over email, please email me. Thanks!


-----Original Message-----
So you're halfway there. Now all you need to do is delete the old key

If you want to remove a key and all it's underlying values then you'll need
to construct your .reg file with a - minus sign in front of the key you want
to remove.

An example file to remove a file association .zzz from HKCR
-----------------Begin File-----------
Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\.zzz]
----------------End File-------------

(note the minus sign in front of HKEY)


If you need to delete only certain values, for example the string value
"InfoTip"="Contains zzz files"

Then put a minus sign after the equals sign
without "quotes", something like
"InfoTip"=-

So your .reg file would look like
----------------Begin File------------
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.zzz]
"InfoTip"=-
----------------End File-------------

regedit /s filename.reg to import silently

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]

Lawrence Lu said:
Ok, sorry for the confusion. Let me give you an example
of what I'm trying to do. In the Windows Registry (as
seen from regedit.exe) there is a tree. Lets say there
is a tree "HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM". What
your saying is that this "tree" is a key? Anyways, what
I would like to do is change the tree's "name" to:
HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM2 . I called them
directories because thats what it looked like in
regedit.exe .

I tried doing this:

[HKEY_LOCAL_MACHINE\SOFTWARE\]
"MYPROGRAM"="MYPROGRAM2"

But that added a key to the \Software\ tree.

Thanks


.
 
That "rename" operation is a function of the GUI
regedit.exe. There
is no rename capability when using .REG files.
It looks like you are on to reg.exe and the copy-to-a-new- keyname,
then delete the old key method. That should work for you I think.

It is also possible to do this by way of .reg files, but it is not a
"rename" per se.

Always backup the entire registry beforehand for safety and recovery
in case things go wrong.

Could you give me a brief example of a .reg file that
would do such a thing? Right now I would like to stray
away from using REG.exe. Thanks!
 
Lawrence Lu wrote in
Could you give me a brief example of a .reg file that
would do such a thing? Right now I would like to stray
away from using REG.exe. Thanks!

I think Dave already covered that in concept.
Let's say I have a key.
HKEY_CURRENT_USER\TEST
I _export_ that key (and contents) to a .REG file. I then edit the
file changing every instance of the key's name from "TEST" to
"TEST2" and save the file. If I then merge that file I will have
accomplished a "copy key TEST to TEST2" action. If I then use the
"remove key" format in a .REG file to remove the TEST key, I end up
with a "rename" TEST to TEST2 equivalent as the end result.

Always backup the entire registry beforehand for safety and recovery
in case things go wrong. And even safer perhaps while you are
experimenting is to create a new user account and profile and work
within the HKCU branch of the registry.
 
For some reason when i do something like:
REG COPY HKLM\Software\MyCo\MyApp
HKLM\Software\MyCo\SaveMyApp /s

it says: Connecting to remote machine \\/s

what do i need to do so it doesnt do this?

Thanks

-----Original Message-----
Use reg.exe from the Windows 2000 Support Tools, located on the Windows 2000
operating system CD-ROM in the \support directory. The Support Tools must be
installed separately from the Windows 2000 operating system

D:\>reg copy /?

Console Registry Tool for Windows - version 3.0
Copyright (C) Microsoft Corp. 1981-2001. All rights reserved


REG COPY KeyName1 KeyName2 [/s] [/f]

KeyName [\\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the current
machine
Only HKLM and HKU are available on remote machines
FullKey ROOTKEY\SubKey
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY
/s Copies all subkeys and values
/f Forces the copy without propmt

Examples:

REG COPY HKLM\Software\MyCo\MyApp
HKLM\Software\MyCo\SaveMyApp /s
Copies all subkeys and values under the key MyApp to the key SaveMyApp

REG COPY \\ZODIAC\HKLM\Software\MyCo HKLM\Software\MyCo1
Copies all values under the key MyCo on ZODIAC to the key MyCo1
on the current machine

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]

Lawrence Lu said:
Ok thanks, that will be helpful, but that doesn't really
solve the initial problem. Let me see if I can describe
it better.

Open regedit, then go to a tree, lets
say "HKEY_LOCAL_MACHINE\SOFTWARE". Then right click on
this "folder" (it looks like a folder!) and then select
Rename, then rename it to something else. This is what I
am trying to do. From what you said in your previous
post is that everything in the registry is a key, but
where do these "directories" (i dont know what else to
call them) exist so i can change them?

Like I said in my previous post, when I tried:
[HKEY_LOCAL_MACHINE\SOFTWARE\]
"MYPROGRAM"="MYPROGRAM2"

It didn't actually RENAME the tree to the new name. The
tree HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM was untouched,
and instead there was a key in
HKEY_LOCAL_MACHINE\SOFTWARE\ which was MYPROGRAM =
MYPROGRAM2.

Is this making sense? If it would be easier to discuss
over email, please email me. Thanks!


.
 
Back
Top