Tales from the Community – Deleting registry values

Okay, I've seen this question in the Technet Forums that basically goes like this:

"Hey I have this reg script that deletes a value off the registry for me. The .reg file does

[HKEY_CLASSES_ROOT\.ext\someApplication\ShellNew]

"FileName"=-

 

- can I do that with an ADM template? All I have is

 

CLASS MACHINE

CATEGORY "Software\CLASSES\.ext\someApplication\ShellNew"
KEYNAME "Software\CLASSES\.ext\someApplication\ShellNew"

 POLICY "FileName"
 PART "FileName"
 NUMERIC
 VALUENAME "FileName"
 END PART
 END POLICY

END CATEGORY

but that doesn't work!"

 

Okay, so let's disassemble this. From the .REG file output, the poster already figured out correctly, that HKEY_CLASSES_ROOT is a substitution for HKLM\SOFTWARE\CLASSES or HKCU\SOFTWARE\CLASSES depending on whether you want the setting stick for users or all users on a machine. Obviously the poster decided to use that as a machine setting, hence CLASS MACHINE.

Unfortunately, the NUMERIC PART isn't capable of deleting keys (at least not that I knew), so we need so tricking here to get the key deleted. Using a CHECKBOX PART leaves us the opportunity to use a VALUEON/VALUEOFF pair in our ADM template - and VALUEON/VALUEOFF know the "DELETE" keyword -- off we go:

CLASS MACHINE

 

CATEGORY "Florians testing"

KEYNAME "Software\FlorianTesting"

 

POLICY "FileName"

PART "FileName" CHECKBOX

VALUENAME "myTest"

VALUEON DELETE

VALUEOFF 2

END PART

END POLICY

 

END CATEGORY

 

So that totally worked for me. The GP setting would display a checkbox when "enabled". If that checkbox is checked, it would delete the value off the registry. If it's unchecked upon closing and saving the setting, it would set the value to 2. That's it. That's all the magic. Worked for me like a charm.

 

That just leave a couple of questions open... why the heck all the hassle with ADM(X)? Seriously, if you've already got hands on a working .REG file, why not deploy it in a computer startup script use regedit /s myFile.reg and forget about the ADM(X) template pain? Better yet, why not use GP Preferences to push the registry deletion to the clients? Since it's *this* cool, I thought I'd paste a screenshot to guide you there:

 

 

 

I must admit I've been a fan of ADM template. They were just kind of geeky and they were kind of a language you could show your friends you understood. But hey, we're in 2010 now. Let's move on :-)

 Cheers,

Florian (Group Policy MVP)