void Walk(RegistryKey parentKey, string[] names, ExpectKeyFoundAction ifFoundAction, bool create = false, int nextNameIndex = 0)
 {
     if (nextNameIndex < names.Length)
     {
         // This function is recursive because we use
         // ExpectKey() whose using{} block controls
         // destruction.
         ExpectKey(parentKey, names[nextNameIndex], childKey => Walk(childKey, names, ifFoundAction, create, nextNameIndex + 1), create, nextNameIndex + 1 >= names.Length);
     }
     else
     {
         ifFoundAction(parentKey);
     }
 }
 void ExpectKey(RegistryKey parent, string name, ExpectKeyFoundAction ifFoundAction, bool create = false, bool writable = false)
 {
     Console.Error.WriteLine("Opening {0}/{1}. create={2}", parent.Name, name, create);
     using (var key = parent.OpenSubKey(name, writable) ?? (create ? parent.CreateSubKey(name) : null))
     {
         if (key == null)
         {
             Console.Error.WriteLine("Could not open {0}.", name);
         }
         else
         {
             ifFoundAction(key);
         }
     }
 }