def AddKeyByPath(self, key_path, registry_key):
if not key_path.startswith(definitions.KEY_PATH_SEPARATOR):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(<EOL>definitions.KEY_PATH_SEPARATOR))<EOL><DEDENT>if not self._root_key:<EOL><INDENT>self._root_key = FakeWinRegistryKey(self._key_path_prefix)<EOL><DEDENT>path_segments = key_paths.SplitKeyPath(key_path)<EOL>parent_key = self._root_key<EOL>for path_segment in path_segments:<EOL><INDENT>try:<EOL><INDENT>subkey = FakeWinRegistryKey(path_segment)<EOL>parent_key.AddSubkey(subkey)<EOL><DEDENT>except KeyError:<EOL><INDENT>subkey = parent_key.GetSubkeyByName(path_segment)<EOL><DEDENT>parent_key = subkey<EOL><DEDENT>parent_key.AddSubkey(registry_key)<EOL>
Adds a Windows Registry key for a specific key path.

        Args:
          key_path (str): Windows Registry key path to add the key.
          registry_key (WinRegistryKey): Windows Registry key.

        Raises:
          KeyError: if the subkey already exists.
          ValueError: if the Windows Registry key cannot be added.