memstechtips/Winhance · error · Exception
winget install Microsoft.OSCDIMG failed with exit code: {exi
Error message
winget install Microsoft.OSCDIMG failed with exit code: {exitCode} What it means
The lightweight Microsoft.OSCDIMG winget package (a smaller alternative to the full ADK that ships just oscdimg.exe) failed to install: winget exited non-zero. OscdimgToolManager runs `winget install Microsoft.OSCDIMG --exact --silent --scope machine --accept-package-agreements --accept-source-agreements` and throws a plain Exception when exitCode != 0.
Source
Thrown at src/Winhance.Infrastructure/Features/AdvancedTools/Services/OscdimgToolManager.cs:370
return false;
}
}
progress?.Report(new TaskProgressDetail
{
StatusText = "Installing Microsoft.OSCDIMG package...",
TerminalOutput = "Installing lightweight oscdimg package via winget"
});
var arguments = "install Microsoft.OSCDIMG --exact --silent --scope machine --accept-package-agreements --accept-source-agreements";
var wingetExe = WinGetCliRunner.GetWinGetExePath() ?? "winget";
_logService.LogInformation($"Using winget for OSCDIMG install: {wingetExe}");
var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
{
throw new Exception($"winget install Microsoft.OSCDIMG failed with exit code: {exitCode}");
}
if (await IsOscdimgAvailableAsync().ConfigureAwait(false))
{
_logService.LogInformation("Microsoft.OSCDIMG package installed via winget and oscdimg.exe found");
return true;
}
_logService.LogError("Microsoft.OSCDIMG package installed via winget but oscdimg.exe not found");
return false;
}
catch (Exception ex)
{
_logService.LogError($"Error installing Microsoft.OSCDIMG package via winget: {ex.Message}", ex);
return false;
}
}
}
View on GitHub (pinned to f23d554eb2)
Solutions
- Run `winget install Microsoft.OSCDIMG --exact --silent --scope machine --accept-package-agreements --accept-source-agreements` manually elevated to read winget's error.
- Update App Installer (winget) from the Microsoft Store to the latest version supporting --scope machine and --accept-source-agreements.
- Run elevated; machine-scope install requires administrator privileges.
- Run `winget search Microsoft.OSCDIMG` to confirm the package exists in the configured sources; if not, `winget source update` or add the right source.
- Fall back to installing the full ADK Deployment Tools (InstallA dkAsync) or a direct oscdimg.exe drop-in.
Example fix
// before
if (exitCode != 0)
throw new Exception($"winget install Microsoft.OSCDIMG failed with exit code: {exitCode}");
// after: surface winget output so the failure is self-explanatory
var (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
throw new Exception($"winget install Microsoft.OSCDIMG failed with exit code {exitCode}. Output: {output}"); Defensive patterns
Strategy: fallback
Validate before calling
bool IsPackageInSources(string packageId)
{
var (output, _, exitCode) = LaunchPowerShellSync($"winget search {packageId} --exact");
return exitCode == 0 && output.Contains(packageId);
} Try / catch
catch (Exception ex) when (ex.Message.Contains("Microsoft.OSCDIMG failed"))
{
// Fall back to full ADK Deployment Tools install, or drop oscdimg.exe in manually.
} Prevention
- Update App Installer so --scope machine and --accept-source-agreements are supported.
- Run elevated for machine-scope installs.
- Confirm `winget search Microsoft.OSCDIMG` finds the package before invoking install.
When it happens
Trigger: InstallOscdimgViaWingetAsync runs the Microsoft.OSCDIMG install; winget returns non-zero. The package id is not found in any configured source, the source is offline/unreachable, App Installer is too old to recognize --scope machine or --exact, or the user context cannot install machine-scope.
Common situations: winget source list does not include the source that hosts Microsoft.OSCDIMG. Corporate policy blocks winget installs. App Installer version predates the --accept-source-agreements flag (it errors out instead of ignoring it). Machine-scope install attempted from a non-elevated process.
Related errors
- winget install failed with exit code: {exitCode}
- ADK installation failed with exit code: {exitCode}
- oscdimg.exe failed with exit code: {exitCode}
- DISM Export-Driver failed with exit code: {exitCode}
- DISM failed with exit code: {exitCode}
AI-assisted analysis of memstechtips/Winhance@f23d554eb2 (2026-08-13).
Data as JSON: /api/errors/9374813aefad7821.
Report an issue: GitHub.