itsfatduck/optimizerDuck · error · StepExecutionException
result.Error ?? Description
Error message
result.Error ?? Description
What it means
ServiceRevertStep.ExecuteAsync throws StepExecutionException with result.Error (falling back to Description) when the sc.exe command that changes the service startup type itself failed with a non-access-denied error. The access-denied message is handled separately (returns false), everything else is surfaced as-is with its error detail.
Solutions
- Read result.ErrorDetail in the exception for the underlying sc.exe output; address that specific cause.
- Confirm the service exists: sc query <ServiceName>. If it was uninstalled, nothing needs reverting — delete the revert file.
- Re-run as administrator to rule out elevated-only failures.
- Retry later if a pending install/uninstall is holding the service.
Defensive patterns
Strategy: try-catch
Validate before calling
var psi = new ProcessStartInfo("sc.exe", $"query {serviceName}") { RedirectStandardOutput = true };
bool exists = psi.Run() == 0; // only revert if the service still exists Try / catch
try { await step.ExecuteAsync(opCall); }
catch (StepExecutionException ex)
{ logger.LogError(ex.Detail ?? ex.Message, "Service revert command failed"); } Prevention
- Confirm the service exists right before reverting
- Run elevated
- Do not uninstall vendor software mid-revert
- Keep sc.exe output parsing current with Windows versions
When it happens
Trigger: Reverting a service startup type where the sc config / process invocation failed: service name invalid, service being deleted, dependency conflicts, or any non-zero exit that is not the recognized access-denied string. result.Error is the provider-captured error text (or Description if empty).
Common situations: Service uninstalled between apply and revert; service display changed; antivirus blocking service configuration changes; running without elevation though the check is via string match so other failures still land here.
Related errors
- Service verify failed for
- Service verify failed for
- Scheduled task verify failed at
- Scheduled task verify failed at
- Missing required 'OriginalEnabled' in scheduled-task revert…
AI-assisted analysis of itsfatduck/optimizerDuck@36acf585ae (2026-09-13).
Data as JSON: /api/errors/e0dcfe425f5927cd.
Report an issue: GitHub.
Appendix: source
Thrown at optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs:56
var opCall = new OpCall { Logger = logger };
var result = await ServiceProcessService
.ChangeServiceStartupTypeAsync(
opCall,
new ServiceItem { Name = ServiceName, StartupType = OriginalStartupType }
)
.ConfigureAwait(false);
if (!result.Ok)
{
// Fail closed: access-denied returns false so RevertManager records a failed
// step; every other failure throws with provider error detail.
var accessDenied = ServiceStrings.Format(
ServiceStrings.ServiceInfoSkippedAccessDenied,
ServiceName
);
if (string.Equals(result.Error, accessDenied, StringComparison.Ordinal))
return false;
throw new StepExecutionException(result.Error ?? Description, result.ErrorDetail);
}
var (actual, notFound) = await ServiceProcessService
.GetStartupTypeAsync(ServiceName, opCall.Logger)
.ConfigureAwait(false);
// a missing service has nothing to restore.
if (notFound)
return true;
// null without NotFound means the query failed; never report an unverified restore.
if (actual is null)
throw new StepExecutionException(
$"Service verify failed for {ServiceName}: could not query the current startup type.",
null
);
if (actual.Value != OriginalStartupType)View on GitHub (pinned to 36acf585ae)