memstechtips/Winhance · warning · Exception
DISM Export-Driver failed with exit code: {exitCode}
Error message
DISM Export-Driver failed with exit code: {exitCode} What it means
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.
Source
Thrown at src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimCustomizationService.cs:71
TerminalOutput = "This may take several minutes"
});
var tempDriverPath = _fileSystemService.CombinePath(_fileSystemService.GetTempPath(), $"WinhanceDrivers_{Guid.NewGuid()}");
_fileSystemService.CreateDirectory(tempDriverPath);
try
{
var arguments = $"/Online /Export-Driver /Destination:\"{tempDriverPath}\"";
progress?.Report(new TaskProgressDetail
{
TerminalOutput = "Exporting drivers from current system..."
});
var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync("dism.exe", arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
{
throw new Exception($"DISM Export-Driver failed with exit code: {exitCode}");
}
sourceDirectory = tempDriverPath;
}
catch (Exception ex)
{
try { _fileSystemService.DeleteDirectory(tempDriverPath, recursive: true); } catch (Exception cleanupEx) { _logService.LogDebug($"Best-effort temp driver directory cleanup failed: {cleanupEx.Message}"); }
_logService.LogError($"Failed to export system drivers: {ex.Message}", ex);
return false;
}
}
else
{
progress?.Report(new TaskProgressDetail
{
StatusText = _localization.GetString("Progress_ValidatingDrivers"),
TerminalOutput = driverSourcePath
});
View on GitHub (pinned to f23d554eb2)
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).
Example fix
// before
var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync("dism.exe", arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
throw new Exception($"DISM Export-Driver failed with exit code: {exitCode}");
// after: capture DISM output for diagnostics; the surrounding catch already soft-fails
var (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync("dism.exe", arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
throw new Exception($"DISM Export-Driver failed with exit code {exitCode}. DISM output: {output}"); Defensive patterns
Strategy: fallback
Validate before calling
// DISM /Online operations require elevation.
bool IsElevated() =>
System.Security.Principal.WindowsIdentity.GetCurrent().Owner
.Equals(new System.Security.Principal.SecurityIdentifier("S-1-5-32-544")); // Administrators RID Try / catch
// The method already catches and returns false; at the call site:
if (!await ExportCurrentSystemDriversAsync(progress, ct).ConfigureAwait(false))
{
// Log and continue WIM customization WITHOUT local drivers — driver export is best-effort.
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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`).
Related errors
- DISM failed with exit code: {exitCode}
- oscdimg.exe failed with exit code: {exitCode}
- ADK installation failed with exit code: {exitCode}
- winget install failed with exit code: {exitCode}
- winget install Microsoft.OSCDIMG failed with exit code: {exi
AI-assisted analysis of memstechtips/Winhance@f23d554eb2 (2026-08-13).
Data as JSON: /api/errors/fa10b42eb9c8805a.
Report an issue: GitHub.