Create script for Brother printer driver #83

This commit is contained in:
Michael H.G. Schmidt 2023-02-01 23:32:30 +01:00
parent e86a325c76
commit 6cf1a06b3c

59
tools/install-printer.cmd Normal file
View File

@ -0,0 +1,59 @@
@echo off
IF %1.==. GOTO USAGE
IF %2.==. GOTO USAGE
IF %3.==. GOTO USAGE
IF %4.==. GOTO USAGE
set DRIVERPATH=%1%
set DRIVERNAME=%2%
set PRINTERIP=%3%
set PRINTERNAME=%4%
set PORTNAME=IP_%PRINTERIP%
if NOT EXIST %DRIVERPATH% (
echo ERROR: %DRIVERPATH% not found!
exit /b
)
rem install the inf files ...
PNPUtil.exe /add-driver %DRIVERPATH%\*.inf /install
rem add the printer driver ...
powershell -Command "Add-PrinterDriver -Name '%DRIVERNAME%' -Verbose"
rem add the printer port ...
powershell -Command ^
"$checkPortExists = Get-Printerport -Name %PORTNAME% -ErrorAction SilentlyContinue ; ^
if (-not $checkPortExists) { ^
Add-PrinterPort -Name %PORTNAME% -PrinterHostAddress %PRINTERIP% -Verbose ^
} else { ^
Write-Host 'Printerport %PORTNAME% already installed' ^
}"
rem add the printer ...
powershell -Command ^
"$checkPrinterExists = Get-Printer -Name '%PRINTERNAME%' -ErrorAction SilentlyContinue ; ^
if (-not $checkPrinterExists) { ^
Add-Printer -Name '%PRINTERNAME%' -DriverName '%DRIVERNAME%' -PortName %PORTNAME% -Verbose ^
} else { ^
Write-Host 'Printer %PRINTERNAME% already installed' ^
}"
echo.
echo setting default printer to [ %PRINTERNAME% ]
powershell -Command ^
"Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows' ^
-Name LegacyDefaultPrinterMode -Value 1 -Force"
powershell -Command "$Printer = Get-CimInstance -Class Win32_Printer -Filter \"Name='%PRINTERNAME%'\"" ; ^
Write-Host $Printer ; ^
Invoke-CimMethod -InputObject $Printer -MethodName SetDefaultPrinter"
GOTO END
:USAGE
echo "usage: %0 <DRIVERPATH> <DRIVERNAME> <PRINTERIP> <PRINTERNAME>"
:END