BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException
Path cannot point to a root key
Error message
Path cannot point to a root key
What it means
Thrown by RemoveRegistryKey when fullRegistryPath contains fewer than 2 backslashes (localized key RegistryTools_RemoveRegistryKey_PointsAtRoot). The library forbids deleting a registry root or a direct child of the root; you must specify a key at least two levels deep (e.g. HKLM\\Software\\App has 2 backslashes).
Source
Thrown at source/KlocTools/Tools/RegistryTools.cs:352
/*/// <exception cref="ArgumentException">Path can't be empty or null</exception>
public static string GetParentRegistryPath(string fullRegistryPath)
{
if (string.IsNullOrEmpty(fullRegistryPath))
throw new ArgumentException("Path can't be empty or null", "fullRegistryPath");
fullRegistryPath.TrimEnd('\\');
var lastIndex = fullRegistryPath.LastIndexOf('\\');
return fullRegistryPath.Substring(0, lastIndex);
}*/
public static void RemoveRegistryKey(string fullRegistryPath)
{
if (string.IsNullOrEmpty(fullRegistryPath))
throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PathEmptyNull,
nameof(fullRegistryPath));
if (fullRegistryPath.Count(x => x.Equals('\\')) < 2)
throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PointsAtRoot,
nameof(fullRegistryPath));
using (var key = OpenRegistryKey(Path.GetDirectoryName(fullRegistryPath), true))
{
if (key != null)
{
var subkeyName = Path.GetFileName(fullRegistryPath);
// Check if key exists before attempting to remove to avoid an exception
if (key.GetSubKeyNames().Contains(subkeyName, StringComparison.OrdinalIgnoreCase))
key.DeleteSubKeyTree(subkeyName);
}
}
}
public static void RemoveRegistryValue(string fullRegistryPath, string valueName)
{
if (string.IsNullOrEmpty(fullRegistryPath))
throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PathEmptyNull,View on GitHub (pinned to 608321de98)
Solutions
- Ensure the path has at least two backslashes, e.g. 'HKCU\\Software\\MyApp'.
- For deleting a direct child of a root, use Registry.LocalMachine.DeleteSubKey directly with explicit intent rather than this helper.
- Add a UI-side confirmation that refuses selections whose backslash count is under 2.
Example fix
// before
RegistryTools.RemoveRegistryKey("HKLM\\Software"); // only 1 backslash
// after
RegistryTools.RemoveRegistryKey("HKLM\\Software\\MyApp"); // 2 backslashes, safe Defensive patterns
Strategy: validation
Validate before calling
if (fullRegistryPath.Count(c => c == '\\') < 2)
throw new InvalidOperationException("Refusing to delete a root or first-level key: " + fullRegistryPath); Type guard
static bool IsDeepEnoughToDelete(string s) =>
!string.IsNullOrWhiteSpace(s) && s.Count(c => c == '\\') >= 2; Try / catch
try { RegistryTools.RemoveRegistryKey(path); }
catch (ArgumentException ex) when (ex.Message.Contains("root"))
{ /* tell user this key is protected */ } Prevention
- Disable the delete action in the UI for top-level nodes.
- Recompute the backslash count after any path trimming.
- Treat the guard as a feature: it prevents wiping hive-level keys.
When it happens
Trigger: Calling RemoveRegistryKey with 'HKLM', 'HKLM\\Software', or any path where Count('\\') < 2.
Common situations: User selecting a top-level node in a registry browser; auto-generated cleanup targeting a hive-wide key; off-by-one in path trimming that drops the leaf segment.
Related errors
- Cannot remove the default value
- Path root is invalid or missing
- Path cannot be empty or null
- Path does not point to a valid .reg file
- Path is too short/invalid
AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13).
Data as JSON: /api/errors/e74710a6f06d11b5.
Report an issue: GitHub.