BCUninstaller/Bulk-Crap-Uninstaller · error · IOException

regedit.exe returned error code: {pr.ExitCode}

Error message

regedit.exe returned error code: {pr.ExitCode}

What it means

Thrown by RunRegeditCommand when regedit.exe exits with a non-zero exit code within the timeout. The message embeds the actual code (e.g. 'regedit.exe returned error code: 1'). regedit is invoked with /e to export, so a non-zero exit typically means the target key does not exist, the path syntax was rejected, or access was denied.

Source

Thrown at source/KlocTools/Tools/RegistryTools.cs:406

        {
            foreach (var process in Process.GetProcessesByName("regedit"))
            {
                try { process.Kill(); }
                catch (InvalidOperationException) { }
                catch (Win32Exception) { }
            }

            var startInfo = new ProcessStartInfo("regedit.exe", command)
            { UseShellExecute = false };
            var pr = startInfo.Start();

            if (!pr.WaitForExit(50000))
            {
                pr.Kill();
                throw new IOException("regedit.exe failed to execute properly");
            }
            if (pr.ExitCode != 0)
                throw new IOException("regedit.exe returned error code: " + pr.ExitCode);
        }

        private static string[] ExportRegistryHelper(string registryPath)
        {
            // Check if the key exists
            try
            {
                OpenRegistryKey(registryPath).Close();
            }
            catch
            {
                return null;
            }

            var temp = Path.GetTempPath();
            var tempDirectory = Directory.CreateDirectory(Path.Combine(temp, "BCU"));
            var tempFile = Path.Combine(tempDirectory.FullName, "tempBackup.reg");

View on GitHub (pinned to 608321de98)

Solutions

  1. Verify the key exists immediately before export (the helper already does an OpenRegistryKey check; ensure your path matches).
  2. Run the process elevated so regedit can read the target hive.
  3. Sanitize the path for quotes/backslashes and confirm the temp directory is writable.
  4. Capture pr.ExitCode in your own log to map the code to a cause (regedit uses generic non-zero for most failures).

Example fix

// before
var lines = ExportRegistryHelper(userPath); // userPath may not exist

// after
if (RegistryTools.OpenRegistryKey(userPath) != null)
    var lines = ExportRegistryHelper(userPath);
Defensive patterns

Strategy: try-catch

Validate before calling

if (RegistryTools.OpenRegistryKey(registryPath) == null)
    return null; // key missing; regedit would exit non-zero

Try / catch

try { var lines = ExportRegistryHelper(path); }
catch (IOException ex) when (ex.Message.Contains("error code"))
{ var code = ex.Message; /* parse code, log, surface actionable message */ }

Prevention

When it happens

Trigger: Exporting a registry path that does not exist; passing a malformed path to regedit; running without privileges to read the requested hive; tempFile path containing characters regedit rejects.

Common situations: Keys deleted between the existence pre-check and the export; paths with embedded quotes that break the /e argument quoting; non-admin process exporting from HKLM; locale-specific path separators.

Related errors


AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13). Data as JSON: /api/errors/3257c8f5bd657e28. Report an issue: GitHub.