added three installation modes
This commit is contained in:
parent
ddfe77154a
commit
e77f4a12c6
|
|
@ -631,29 +631,84 @@ function Restore-PrinterDriver {
|
|||
}
|
||||
|
||||
if ($infPath) {
|
||||
try {
|
||||
Write-Log " Treiber installieren via INF: $(Split-Path -Leaf $infPath)"
|
||||
|
||||
# Treiber zum DriverStore hinzufuegen
|
||||
# Schritt 1: Treiberpaket zum DriverStore hinzufuegen via pnputil
|
||||
$publishedInfPath = $null
|
||||
try {
|
||||
$pnpResult = & pnputil.exe /add-driver "$infPath" /install 2>&1
|
||||
$pnpOutput = ($pnpResult | Out-String).Trim()
|
||||
if ($pnpOutput) {
|
||||
Write-Log " pnputil: $pnpOutput"
|
||||
|
||||
# Veroeffentlichten INF-Namen aus pnputil-Ausgabe extrahieren (z.B. oem60.inf)
|
||||
if ($pnpOutput -match '(oem\d+\.inf)') {
|
||||
$publishedInf = $matches[1]
|
||||
$publishedInfPath = Join-Path "$env:SystemRoot\INF" $publishedInf
|
||||
Write-Log " Veroeffentlichte INF: $publishedInfPath"
|
||||
}
|
||||
} catch {
|
||||
Write-Log " Warnung: pnputil fehlgeschlagen: $_"
|
||||
}
|
||||
|
||||
# Druckertreiber registrieren
|
||||
Add-PrinterDriver -Name $driverName -InfPath $infPath -ErrorAction Stop
|
||||
Write-Log " Treiber '$driverName' erfolgreich installiert."
|
||||
return $true
|
||||
# Schritt 2: Druckertreiber registrieren - mehrere Methoden versuchen
|
||||
$driverAdded = $false
|
||||
|
||||
# Methode A: Mit veroeffentlichter INF aus dem DriverStore
|
||||
if (-not $driverAdded -and $publishedInfPath -and (Test-Path -LiteralPath $publishedInfPath)) {
|
||||
try {
|
||||
Add-PrinterDriver -Name $driverName -InfPath $publishedInfPath -ErrorAction Stop
|
||||
Write-Log " Treiber '$driverName' erfolgreich installiert (via DriverStore)."
|
||||
$driverAdded = $true
|
||||
} catch {
|
||||
Write-Log " Warnung: INF-Installation fehlgeschlagen: $_"
|
||||
# Pruefen ob pnputil den Treiber trotzdem installiert hat
|
||||
$retryDriver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
||||
if ($retryDriver) {
|
||||
Write-Log " Treiber wurde dennoch gefunden - OK."
|
||||
return $true
|
||||
Write-Log " Methode A (DriverStore-INF) fehlgeschlagen: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Methode B: Mit original Backup-INF
|
||||
if (-not $driverAdded) {
|
||||
try {
|
||||
Add-PrinterDriver -Name $driverName -InfPath $infPath -ErrorAction Stop
|
||||
Write-Log " Treiber '$driverName' erfolgreich installiert (via Backup-INF)."
|
||||
$driverAdded = $true
|
||||
} catch {
|
||||
Write-Log " Methode B (Backup-INF) fehlgeschlagen: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Methode C: printui.dll verwenden (robuster bei OEM-Treibern)
|
||||
if (-not $driverAdded) {
|
||||
$tryInf = if ($publishedInfPath -and (Test-Path -LiteralPath $publishedInfPath)) {
|
||||
$publishedInfPath
|
||||
} else {
|
||||
$infPath
|
||||
}
|
||||
try {
|
||||
Write-Log " Versuche printui.dll..."
|
||||
$printUiArgs = "printui.dll,PrintUIEntry /ia /m `"$driverName`" /f `"$tryInf`""
|
||||
Start-Process rundll32.exe -ArgumentList $printUiArgs -Wait -NoNewWindow -ErrorAction Stop
|
||||
Start-Sleep -Milliseconds 1000
|
||||
$check = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
||||
if ($check) {
|
||||
Write-Log " Treiber '$driverName' erfolgreich installiert (via printui)."
|
||||
$driverAdded = $true
|
||||
} else {
|
||||
Write-Log " Methode C (printui) fehlgeschlagen."
|
||||
}
|
||||
} catch {
|
||||
Write-Log " Methode C (printui) fehlgeschlagen: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Letzte Pruefung: Vielleicht wurde der Treiber doch registriert
|
||||
if (-not $driverAdded) {
|
||||
$finalCheck = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
||||
if ($finalCheck) {
|
||||
Write-Log " Treiber '$driverName' ist jetzt verfuegbar."
|
||||
$driverAdded = $true
|
||||
}
|
||||
}
|
||||
|
||||
if ($driverAdded) { return $true }
|
||||
}
|
||||
|
||||
Write-Log " Fehler: Treiber '$driverName' konnte nicht installiert werden." "ERROR"
|
||||
|
|
|
|||
Loading…
Reference in New Issue