{"record":{"id":"3257c8f5bd657e28","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"regedit-exe-returned-error-code-pr-exitcode","errorCode":null,"errorMessage":"regedit.exe returned error code: {pr.ExitCode}","messagePattern":"regedit\\.exe returned error code: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Tools/RegistryTools.cs","lineNumber":406,"sourceCode":"        {\n            foreach (var process in Process.GetProcessesByName(\"regedit\"))\n            {\n                try { process.Kill(); }\n                catch (InvalidOperationException) { }\n                catch (Win32Exception) { }\n            }\n\n            var startInfo = new ProcessStartInfo(\"regedit.exe\", command)\n            { UseShellExecute = false };\n            var pr = startInfo.Start();\n\n            if (!pr.WaitForExit(50000))\n            {\n                pr.Kill();\n                throw new IOException(\"regedit.exe failed to execute properly\");\n            }\n            if (pr.ExitCode != 0)\n                throw new IOException(\"regedit.exe returned error code: \" + pr.ExitCode);\n        }\n\n        private static string[] ExportRegistryHelper(string registryPath)\n        {\n            // Check if the key exists\n            try\n            {\n                OpenRegistryKey(registryPath).Close();\n            }\n            catch\n            {\n                return null;\n            }\n\n            var temp = Path.GetTempPath();\n            var tempDirectory = Directory.CreateDirectory(Path.Combine(temp, \"BCU\"));\n            var tempFile = Path.Combine(tempDirectory.FullName, \"tempBackup.reg\");\n","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Tools/RegistryTools.cs#L388-L424","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the key exists immediately before export (the helper already does an OpenRegistryKey check; ensure your path matches).","Run the process elevated so regedit can read the target hive.","Sanitize the path for quotes/backslashes and confirm the temp directory is writable.","Capture pr.ExitCode in your own log to map the code to a cause (regedit uses generic non-zero for most failures)."],"exampleFix":"// before\nvar lines = ExportRegistryHelper(userPath); // userPath may not exist\n\n// after\nif (RegistryTools.OpenRegistryKey(userPath) != null)\n    var lines = ExportRegistryHelper(userPath);","handlingStrategy":"try-catch","validationCode":"if (RegistryTools.OpenRegistryKey(registryPath) == null)\n    return null; // key missing; regedit would exit non-zero","typeGuard":null,"tryCatchPattern":"try { var lines = ExportRegistryHelper(path); }\ncatch (IOException ex) when (ex.Message.Contains(\"error code\"))\n{ var code = ex.Message; /* parse code, log, surface actionable message */ }","preventionTips":["Verify the key exists immediately before export.","Run elevated when exporting from HKLM.","Sanitize path quoting passed to the helper."],"tags":["registry","process","regedit","error-code","windows","csharp"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}