{"record":{"id":"9374813aefad7821","repo":"memstechtips/Winhance","slug":"winget-install-microsoft-oscdimg-failed-with-exit","errorCode":null,"errorMessage":"winget install Microsoft.OSCDIMG failed with exit code: {exitCode}","messagePattern":"winget install Microsoft\\.OSCDIMG failed with exit code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Winhance.Infrastructure/Features/AdvancedTools/Services/OscdimgToolManager.cs","lineNumber":370,"sourceCode":"                    return false;\r\n                }\r\n            }\r\n\r\n            progress?.Report(new TaskProgressDetail\r\n            {\r\n                StatusText = \"Installing Microsoft.OSCDIMG package...\",\r\n                TerminalOutput = \"Installing lightweight oscdimg package via winget\"\r\n            });\r\n\r\n            var arguments = \"install Microsoft.OSCDIMG --exact --silent --scope machine --accept-package-agreements --accept-source-agreements\";\r\n\r\n            var wingetExe = WinGetCliRunner.GetWinGetExePath() ?? \"winget\";\r\n            _logService.LogInformation($\"Using winget for OSCDIMG install: {wingetExe}\");\r\n\r\n            var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);\r\n            if (exitCode != 0)\r\n            {\r\n                throw new Exception($\"winget install Microsoft.OSCDIMG failed with exit code: {exitCode}\");\r\n            }\r\n\r\n            if (await IsOscdimgAvailableAsync().ConfigureAwait(false))\r\n            {\r\n                _logService.LogInformation(\"Microsoft.OSCDIMG package installed via winget and oscdimg.exe found\");\r\n                return true;\r\n            }\r\n\r\n            _logService.LogError(\"Microsoft.OSCDIMG package installed via winget but oscdimg.exe not found\");\r\n            return false;\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n            _logService.LogError($\"Error installing Microsoft.OSCDIMG package via winget: {ex.Message}\", ex);\r\n            return false;\r\n        }\r\n    }\r\n}\r","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/AdvancedTools/Services/OscdimgToolManager.cs#L352-L388","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif (exitCode != 0)\n    throw new Exception($\"winget install Microsoft.OSCDIMG failed with exit code: {exitCode}\");\n\n// after: surface winget output so the failure is self-explanatory\nvar (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(wingetExe, arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"winget install Microsoft.OSCDIMG failed with exit code {exitCode}. Output: {output}\");","handlingStrategy":"fallback","validationCode":"bool IsPackageInSources(string packageId)\n{\n    var (output, _, exitCode) = LaunchPowerShellSync($\"winget search {packageId} --exact\");\n    return exitCode == 0 && output.Contains(packageId);\n}","typeGuard":null,"tryCatchPattern":"catch (Exception ex) when (ex.Message.Contains(\"Microsoft.OSCDIMG failed\"))\n{\n    // Fall back to full ADK Deployment Tools install, or drop oscdimg.exe in manually.\n}","preventionTips":["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."],"tags":["installer","winget","external-process","windows","oscdimg","prerequisite"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}