Windows registry delete value oddity

Say I have four registry values under the same key with these names:

  1. ‘this_text’
  2. ‘this_text1’
  3. ‘this_text2’
  4. ‘this_text3’

When I run the script below, two of the values will be deleted. When I
run it again, one value will be deleted. On the third run, the last
value will be deleted. I don’t understand why all of the values are not
deleted on the first run.

Win32::Registry::HKEY_LOCAL_MACHINE.open(key,
Win32::Registry::KEY_ALL_ACCESS) do |reg|

reg.each_value do |name, type, data|

if name.include?('this_text')

  reg.delete_value(name)

end

end

end

Could someone point out what I’m doing wrong?

Thanks,
Brad

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs