{"record":{"id":"5d96f5701cf5f0de","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"regedit-exe-failed-to-execute-properly","errorCode":null,"errorMessage":"regedit.exe failed to execute properly","messagePattern":"regedit\\.exe failed to execute properly","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Tools/RegistryTools.cs","lineNumber":403,"sourceCode":"        }\n\n        private static void RunRegeditCommand(string command)\n        {\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();","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Tools/RegistryTools.cs#L385-L421","documentation":"Thrown by RunRegeditCommand when regedit.exe does not exit within 50000 ms. The helper waits up to 50 seconds for the spawned regedit process; on timeout it kills the process and raises this IOException. It is a fatal, non-retryable outcome from the helper's perspective (the process is already terminated).","triggerScenarios":"Calling ExportRegistryHelper (or any code path that invokes RunRegeditCommand) when regedit.exe hangs, is blocked by a dialog (e.g. UAC, overwrite confirmation), is deadlocked on a locked file, or the system is under heavy load so regedit never returns within 50 s.","commonSituations":"A previous regedit instance holding a lock; antivirus scanning tempBackup.reg; exporting a very large registry subtree that exceeds the timeout; running as a user without permission, causing regedit to wait on a prompt it cannot show.","solutions":["Ensure no interactive regedit dialogs are pending (the helper kills prior regedit instances first, but external UAC prompts can still block).","Reduce the scope of the export so regedit finishes well under 50 s.","Run the process elevated and with an accessible temp directory (the helper uses %TEMP%\\\\BCU\\\\tempBackup.reg).","If 50 s is genuinely too short for your workload, fork the helper and raise the WaitForExit timeout or run regedit asynchronously."],"exampleFix":"// before (uses RunRegeditCommand via ExportRegistryHelper, 50s hard cap)\nvar lines = ExportRegistryHelper(bigSubtreePath);\n\n// after (export a narrower key, or call reg.exe directly with your own timeout)\nvar lines = ExportRegistryHelper(\"HKLM\\\\SOFTWARE\\\\MyApp\");","handlingStrategy":"retry","validationCode":"// Pre-check the key exists and is readable, and that no regedit dialog is pending.\nif (RegistryTools.OpenRegistryKey(registryPath) == null) return null;","typeGuard":null,"tryCatchPattern":"try { var lines = ExportRegistryHelper(path); }\ncatch (IOException ex) when (ex.Message.Contains(\"failed to execute properly\"))\n{ /* regedit was killed; report timeout, optionally retry with a narrower key */ }","preventionTips":["Export narrow subtrees rather than whole hives to stay well under 50 s.","Ensure no UAC/regedit dialogs can block the spawned process.","Confirm %TEMP%\\\\BCU is writable and not scanned by AV."],"tags":["registry","process","timeout","regedit","windows","csharp"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}