Monday, June 8, 2009

Removing registry keys with Regedit

Many times working with sccm we need to push out registry keys which is easy with a .reg file and regedit...."regedit /s key.reg" This adds all your keys to the registry and is very quick at it.

But what if you want to remove keys. Well you can use Vbscript or other lang to edit the registry or you can use a regedit. Yup a special "minus" sign will remove a key or tree.

[HKEY_LOCAL_ MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\xwing]
"key1"="value"
"key2"="value"
"key3"="value"


Say we want to remove the entire tree. We do this by sending the reg file with the following change

[-HKEY_LOCAL_ MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\xwing]

Everything in xwing and sub keys will be deleted.


Now say you want to just delete key2 then you send this
[HKEY_LOCAL_ MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\xwing]
"key2"=-

This will remove only key2 from the registry.

What is nice about this is that it won't throw an error if nothing is there so you can send it down to all machines whether they have the key or not.


MS KB article
http://support.microsoft.com/kb/310516