{"record":{"id":"499d0617360af9d5","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"action-failed-with-return-value-outparams-return","errorCode":null,"errorMessage":"Action failed with return value {outParams[\"ReturnValue\"]}. Check return codes of Win32_Service class methods for more information.","messagePattern":"Action failed with return value (.+?)\\. Check return codes of Win32_Service class methods for more information\\.","errorType":"exception","errorClass":"ManagementException","httpStatus":null,"severity":"error","filePath":"source/UninstallTools/Startup/Service/ServiceEntryFactory.cs","lineNumber":123,"sourceCode":"\r\n            var classInstance = GetServiceObject(serviceName);\r\n\r\n            // Execute the method and obtain the return values.\r\n            var outParams = classInstance.InvokeMethod(\"Delete\", null, new InvokeMethodOptions { Timeout = TimeSpan.FromMinutes(1) });\r\n            CheckReturnValue(outParams, 16); // 16 - Service Marked For Deletion\r\n        }\r\n\r\n        private static void CheckReturnValue(ManagementBaseObject outParams, params UInt32[] ignoredCodes)\r\n        {\r\n            if (outParams == null) return;\r\n\r\n            var exitCode = (UInt32)outParams[\"ReturnValue\"];\r\n            if (exitCode == 0 || ignoredCodes.Any(x => x == exitCode)) return;\r\n\r\n            if (exitCode == 2) // 2 - Access Denied\r\n                throw new SecurityException(\"The user does not have the necessary access.\");\r\n\r\n            throw new ManagementException(\"Action failed with return value \" + outParams[\"ReturnValue\"] +\r\n                \". Check return codes of Win32_Service class methods for more information.\");\r\n        }\r\n\r\n        private static ManagementObject GetServiceObject(string serviceName)\r\n        {\r\n            return new ManagementObject(\"root\\\\CIMV2\",\r\n                $\"Win32_Service.Name='{serviceName}'\", new ObjectGetOptions { Timeout = TimeSpan.FromMinutes(1) });\r\n        }\r\n    }\r\n}","sourceCodeStart":105,"sourceCodeEnd":133,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/UninstallTools/Startup/Service/ServiceEntryFactory.cs#L105-L133","documentation":"The catch-all branch in CheckReturnValue: the WMI ReturnValue is non-zero, not 2 (Access Denied), and not in the ignoredCodes list (e.g. 16 'Marked For Deletion'), so it throws a System.Management.ManagementException with the raw return value and a hint to consult the Win32_Service return-code documentation. Every other failure mode (service not found, dependency running, etc.) lands here.","triggerScenarios":"Any WMI service operation that returns a non-zero code other than the ignored set — e.g. ReturnValue 7 'Service dependency deleted/failed', 8 'Service cannot start', 9 'Service not found', 14 'Service disabled', or the dependency-stop path returning a non-OK code.","commonSituations":"Trying to delete a service that has running dependencies; stopping a service whose recovery policy restarts it immediately; the service was already removed by another tool (code 9); the service is disabled (code 14).","solutions":["Inspect the numeric ReturnValue in the exception message and look it up in the Win32_Service.Create/Delete/StopService return-code table to identify the specific condition.","Stop dependent services first (and disable recovery) before deleting/stopping.","Catch ManagementException, decode the ReturnValue, and either retry with dependencies resolved or report the specific condition to the user."],"exampleFix":"// before\nServiceEntryFactory.Delete(serviceEntry);\n\n// after\ntry { ServiceEntryFactory.Delete(serviceEntry); }\ncatch (ManagementException ex)\n{\n    // ex.Message contains '...return value <N>'. Decode N per Win32_Service docs.\n    logger.Error($\"Service op failed: {ex.Message}\");\n    if (IsDependencyFailure(ex)) StopDependentsFirst(serviceEntry);\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { ServiceEntryFactory.Delete(serviceEntry); }\ncatch (ManagementException ex)\n{\n    var code = ExtractReturnValue(ex.Message);\n    switch (code)\n    {\n        case 14: /* disabled */ EnableService(serviceEntry); ServiceEntryFactory.Delete(serviceEntry); break;\n        case 9:  /* not found */ logger.Warn(\"Service already gone.\"); break;\n        default: throw;\n    }\n}","preventionTips":["Stop dependent services before deleting a service.","Disable service recovery policies that auto-restart during delete.","Decode the numeric ReturnValue against the Win32_Service docs before retrying."],"tags":["windows-service","wmi","management-exception","return-code","dependencies"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}