{"record":{"id":"fa10b42eb9c8805a","repo":"memstechtips/Winhance","slug":"dism-export-driver-failed-with-exit-code-exitcod","errorCode":null,"errorMessage":"DISM Export-Driver failed with exit code: {exitCode}","messagePattern":"DISM Export-Driver failed with exit code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimCustomizationService.cs","lineNumber":71,"sourceCode":"                    TerminalOutput = \"This may take several minutes\"\r\n                });\r\n\r\n                var tempDriverPath = _fileSystemService.CombinePath(_fileSystemService.GetTempPath(), $\"WinhanceDrivers_{Guid.NewGuid()}\");\r\n                _fileSystemService.CreateDirectory(tempDriverPath);\r\n\r\n                try\r\n                {\r\n                    var arguments = $\"/Online /Export-Driver /Destination:\\\"{tempDriverPath}\\\"\";\r\n\r\n                    progress?.Report(new TaskProgressDetail\r\n                    {\r\n                        TerminalOutput = \"Exporting drivers from current system...\"\r\n                    });\r\n\r\n                    var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(\"dism.exe\", arguments, progress, cancellationToken).ConfigureAwait(false);\r\n                    if (exitCode != 0)\r\n                    {\r\n                        throw new Exception($\"DISM Export-Driver failed with exit code: {exitCode}\");\r\n                    }\r\n\r\n                    sourceDirectory = tempDriverPath;\r\n                }\r\n                catch (Exception ex)\r\n                {\r\n                    try { _fileSystemService.DeleteDirectory(tempDriverPath, recursive: true); } catch (Exception cleanupEx) { _logService.LogDebug($\"Best-effort temp driver directory cleanup failed: {cleanupEx.Message}\"); }\r\n                    _logService.LogError($\"Failed to export system drivers: {ex.Message}\", ex);\r\n                    return false;\r\n                }\r\n            }\r\n            else\r\n            {\r\n                progress?.Report(new TaskProgressDetail\r\n                {\r\n                    StatusText = _localization.GetString(\"Progress_ValidatingDrivers\"),\r\n                    TerminalOutput = driverSourcePath\r\n                });\r","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimCustomizationService.cs#L53-L89","documentation":"DISM was invoked as `dism.exe /Online /Export-Driver /Destination:\"<tempDriverPath>\"` to harvest the running system's third-party drivers for injection into the WIM, and DISM exited non-zero. The exception is caught locally, the temp directory is cleaned up best-effort, the error is logged, and the method returns false — so callers see a soft failure, not an exception.","triggerScenarios":"ExportCurrentSystemDriversAsync runs dism.exe /Online /Export-Driver to a temp folder and RunProcessWithProgressAsync returns exitCode != 0. DISM export-driver fails when: the process is not elevated, the online image is busy/servicing-in-progress, the destination path is invalid/unwritable, or DISM is the wrong version for the OS.","commonSituations":"Winhance is running non-elevated, so /Online driver export is denied. A Windows Update or another servicing operation is in progress (DISM returns error 0x800F0906 / CBS_E_PENDING). The temp drive is out of space. DISM on the image is corrupted (needs `sfc /scannow` or `DISM /RestoreHealth`).","solutions":["Run Winhance as administrator — /Online DISM operations require elevation.","Clear pending servicing: reboot, then run `DISM /Online /Cleanup-Image /RestoreHealth` and retry.","Confirm the temp driver path is on a drive with enough free space and is writable.","Inspect the DISM progress output (streamed to TerminalOutput) for the specific DISM error code, then address it.","If driver export keeps failing, proceed with WIM customization without injecting local drivers (the method already returns false to allow that)."],"exampleFix":"// before\nvar (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(\"dism.exe\", arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"DISM Export-Driver failed with exit code: {exitCode}\");\n\n// after: capture DISM output for diagnostics; the surrounding catch already soft-fails\nvar (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(\"dism.exe\", arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"DISM Export-Driver failed with exit code {exitCode}. DISM output: {output}\");","handlingStrategy":"fallback","validationCode":"// DISM /Online operations require elevation.\nbool IsElevated() =>\n    System.Security.Principal.WindowsIdentity.GetCurrent().Owner\n        .Equals(new System.Security.Principal.SecurityIdentifier(\"S-1-5-32-544\")); // Administrators RID","typeGuard":null,"tryCatchPattern":"// The method already catches and returns false; at the call site:\nif (!await ExportCurrentSystemDriversAsync(progress, ct).ConfigureAwait(false))\n{\n    // Log and continue WIM customization WITHOUT local drivers — driver export is best-effort.\n}","preventionTips":["Run Winhance elevated so DISM /Online operations succeed.","Clear pending servicing (reboot + DISM /RestoreHealth) before exporting drivers.","Treat driver export as optional so a failure does not block the rest of WIM customization."],"tags":["dism","external-process","windows","drivers","privilege"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}