Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations

Erase-a-RegKey.

For many years now I've been using .REG files to deploy registry changes - quick, easy and notepad-compatible. The problem is that I could easily add or modify keys with this, but couldn't erase them - there was no notation in the REG file format to erase a key or value - or at least none that I know of...

I don't know which version of Windows first started supporting it, but on Win2000 it works like a charm - when specifying the name of the key, simply add a Minus sign in the beginning, and the key will be wiped clean without a trace.

I don't know if it's possible to erase a value inside a key, too - never tried it. But it wipes a key with all sub-keys and values easily.

Ex:

This creates a key:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\MyStuff]
"MyLittleValue"=dword:00000001

And this erases it!

Windows Registry Editor Version 5.00
[-HKEY_LOCAL_MACHINE\Software\MyStuff]
"MyLittleValue"=dword:00000001 (This line is meaningless when erasing a key).

Comments

AT said:

Your code will delete entire HKEY_LOCAL_MACHINE\Software\MyStuff key.

MyLittleValue line has no any effect in erase file example.


If you need to delete single or multiple values instead of key use:

Delete values:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\MyStuff]
"MyLittleValue"=-
"MyLittleValue2"=-

But if you still need to delete entire key

Windows Registry Editor Version 5.00
[-HKEY_LOCAL_MACHINE\Software\MyStuff]
# May 19, 2004 5:00 PM

Avner Kashtan said:

Aha. I knew there must be a notation to erase a single value, but I didn't know what it was.

Thanks!
# May 20, 2004 1:56 AM

TrackBack said:

I didn't know you could do this; seems like a useful thing to remember. How to erase registry keys using .reg files......
# June 17, 2004 8:08 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)