BCUninstaller/Bulk-Crap-Uninstaller · error · ManagementException
Action failed with return value {outParams["ReturnValue"]}.
Error message
Action failed with return value {outParams["ReturnValue"]}. Check return codes of Win32_Service class methods for more information. What it means
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.
Source
Thrown at source/UninstallTools/Startup/Service/ServiceEntryFactory.cs:123
var classInstance = GetServiceObject(serviceName);
// Execute the method and obtain the return values.
var outParams = classInstance.InvokeMethod("Delete", null, new InvokeMethodOptions { Timeout = TimeSpan.FromMinutes(1) });
CheckReturnValue(outParams, 16); // 16 - Service Marked For Deletion
}
private static void CheckReturnValue(ManagementBaseObject outParams, params UInt32[] ignoredCodes)
{
if (outParams == null) return;
var exitCode = (UInt32)outParams["ReturnValue"];
if (exitCode == 0 || ignoredCodes.Any(x => x == exitCode)) return;
if (exitCode == 2) // 2 - Access Denied
throw new SecurityException("The user does not have the necessary access.");
throw new ManagementException("Action failed with return value " + outParams["ReturnValue"] +
". Check return codes of Win32_Service class methods for more information.");
}
private static ManagementObject GetServiceObject(string serviceName)
{
return new ManagementObject("root\\CIMV2",
$"Win32_Service.Name='{serviceName}'", new ObjectGetOptions { Timeout = TimeSpan.FromMinutes(1) });
}
}
}View on GitHub (pinned to 608321de98)
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.
Example fix
// before
ServiceEntryFactory.Delete(serviceEntry);
// after
try { ServiceEntryFactory.Delete(serviceEntry); }
catch (ManagementException ex)
{
// ex.Message contains '...return value <N>'. Decode N per Win32_Service docs.
logger.Error($"Service op failed: {ex.Message}");
if (IsDependencyFailure(ex)) StopDependentsFirst(serviceEntry);
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try { ServiceEntryFactory.Delete(serviceEntry); }
catch (ManagementException ex)
{
var code = ExtractReturnValue(ex.Message);
switch (code)
{
case 14: /* disabled */ EnableService(serviceEntry); ServiceEntryFactory.Delete(serviceEntry); break;
case 9: /* not found */ logger.Warn("Service already gone."); break;
default: throw;
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- The user does not have the necessary access.
- Win32_Directory.Compress returned {ret}
- Error while collecting Windows Features. If Windows Update i
- WMI query has hung while collecting Windows Features, try re
AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13).
Data as JSON: /api/errors/499d0617360af9d5.
Report an issue: GitHub.