Update samy.ps1
This commit is contained in:
34
samy.ps1
34
samy.ps1
@@ -2141,20 +2141,10 @@ function Ensure-SamyPrinterDriver {
|
|||||||
Write-LogHybrid "Printer driver '$driverName' not found. Preparing to install." Info Printers -LogToEvent
|
Write-LogHybrid "Printer driver '$driverName' not found. Preparing to install." Info Printers -LogToEvent
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# 0) Decide where driver files live locally
|
# 0) Decide where driver files live locally (per-profile)
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
$localDriverRoot = $null
|
$localDriverRoot = Get-SamyDriverFolderForProfile -Profile $Profile
|
||||||
if ($Profile.PSObject.Properties.Name -contains 'DriverInfPath' -and $Profile.DriverInfPath) {
|
|
||||||
$localDriverRoot = Split-Path -Path $Profile.DriverInfPath -Parent
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# Fallback root if no INF path is defined yet
|
|
||||||
$localDriverRoot = "C:\ProgramData\SVS\Samy\Drivers"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not (Test-Path $localDriverRoot)) {
|
|
||||||
New-Item -Path $localDriverRoot -ItemType Directory -Force | Out-Null
|
|
||||||
}
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# 1) Start with any static local INF path, if defined
|
# 1) Start with any static local INF path, if defined
|
||||||
@@ -2269,11 +2259,27 @@ function Ensure-SamyPrinterDriver {
|
|||||||
|
|
||||||
Write-LogHybrid "Installing printer driver '$driverName' from '$infPath'." Info Printers -LogToEvent
|
Write-LogHybrid "Installing printer driver '$driverName' from '$infPath'." Info Printers -LogToEvent
|
||||||
|
|
||||||
pnputil.exe /add-driver "`"$infPath`"" /install | Out-Null
|
Write-LogHybrid "Installing printer driver '$driverName' from '$infPath'." Info Printers -LogToEvent
|
||||||
|
|
||||||
|
# Run pnputil and capture output + exit code
|
||||||
|
$pnputilOutput = & pnputil.exe /add-driver "`"$infPath`"" /install 2>&1
|
||||||
|
$exitCode = $LASTEXITCODE
|
||||||
|
|
||||||
|
Write-LogHybrid "pnputil exit code: $exitCode. Output:`n$pnputilOutput" Info Printers -LogToEvent
|
||||||
|
|
||||||
|
if ($exitCode -ne 0) {
|
||||||
|
throw "pnputil failed with exit code $exitCode. See Printers logs for details."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify driver presence (by name)
|
||||||
$existingDriver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
$existingDriver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
||||||
if (-not $existingDriver) {
|
if (-not $existingDriver) {
|
||||||
throw "Failed to install printer driver '$driverName' from '$infPath'."
|
# Optional: log what SHARP drivers *do* exist to catch name mismatches
|
||||||
|
$sharpNames = (Get-PrinterDriver | Where-Object Name -like '*SHARP*' |
|
||||||
|
Select-Object -ExpandProperty Name) -join ', '
|
||||||
|
|
||||||
|
Write-LogHybrid "After pnputil, driver '$driverName' not found. Existing SHARP drivers: $sharpNames" Warning Printers -LogToEvent
|
||||||
|
throw "Failed to find printer driver '$driverName' after pnputil install."
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-LogHybrid "Printer driver '$driverName' installed successfully." Success Printers -LogToEvent
|
Write-LogHybrid "Printer driver '$driverName' installed successfully." Success Printers -LogToEvent
|
||||||
|
|||||||
Reference in New Issue
Block a user