
@echo off
setlocal enabledelayedexpansion

rem Network install can have 5 parameters (i.e. "silentinstall.cmd network <ip> printSampleCard DisplayDashboard")
rem USB install can have 4 parameters (i.e. "silentinstall.cmd USB printSampleCard DisplayDashboard")
set var=%1

set var2=%2

set OsArch=%PROCESSOR_ARCHITECTURE%

rem If the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending" exists,
rem windows updates are pending.
rem on the following line ">nul 2>&1" redirects STDOUT to nul and STDERR to STDOUT, so no "output" or "error" info is displayed to the user.
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending" >nul 2>&1
if %ERRORLEVEL% == 0 (
    echo Windows updates are pending. Restart the computer to complete the updates before continuing.
    GOTO SyntaxEnd
)

if /i "%var%" == "network" (
    set var=Network
    if "%var2%"=="" (set var2=0.0.0.0)
    echo Begin !var! install, IP = !var2! %3 %4
    start /wait autoplay\networkInstall\%OsArch%\dxp01install.exe network !var2! %3 %4
) else if /i "%var%" == "usb" (
    set var=USB
    echo Begin !var! install, %2 %3
    start /wait autoplay\networkInstall\%OsArch%\dxp01install.exe usb %2 %3
) else if /i "%var%" == "MagstripeFonts" (
    echo Begin %var% 
    start /wait autoplay\networkInstall\%OsArch%\dxp01install.exe MagstripeFonts
) else if /i "%var%" == "LegacyMagstripeFonts" (
    echo Begin %var% 
    start /wait autoplay\networkInstall\%OsArch%\dxp01install.exe LegacyMagstripeFonts
) else if /i "%var%" == "CustomMaskingBitmaps" (
    echo Begin %var% 
    start /wait autoplay\networkInstall\%OsArch%\dxp01install.exe CustomMaskingBitmaps
) else (
    goto Syntax
)

if %ERRORLEVEL% == 0 (
    if /i "%var%" == "network" (
        ECHO Network Printer Driver install successful
    ) else if /i "%var%" == "usb" (
        ECHO USB Printer Driver install successful
        ECHO Connect USB cable to printer.
    ) else if /i "%var%" == "MagstripeFonts" (
        ECHO Printer Driver MagstripeFonts successful
    ) else if /i "%var%" == "LegacyMagstripeFonts" (
        ECHO Printer Driver LegacyMagstripeFonts successful
    ) else if /i "%var%" == "CustomMaskingBitmaps" (
        ECHO Printer Driver CustomMaskingBitmaps successful
    ) 
    GOTO SyntaxEnd
) 
if %ERRORLEVEL% == 1 (
    if /i "%var%" == "network" (
        ECHO Network Printer Driver install failed
    ) else if /i "%var%" == "usb" (
        ECHO USB Printer Driver install failed
    ) else if /i "%var%" == "MagstripeFonts" (
        ECHO Printer Driver MagstripeFonts failed
    ) else if /i "%var%" == "LegacyMagstripeFonts" (
        ECHO Printer Driver LegacyMagstripeFonts failed
    ) else if /i "%var%" == "CustomMaskingBitmaps" (
        ECHO Printer Driver CustomMaskingBitmaps failed
    ) 
    GOTO SyntaxEnd
)
if %ERRORLEVEL% == 2 (
    ECHO !var! Printer Driver update needed
    GOTO SyntaxEnd
)
if %ERRORLEVEL% == 3 (
    ECHO Newer driver already installed
    GOTO SyntaxEnd
)
if %ERRORLEVEL% == 4 (
    ECHO Driver cannot be uninstalled until printers are removed
    ECHO The driver has not been uninstalled.
    GOTO SyntaxEnd
)
if %ERRORLEVEL% == 5 (
    ECHO !var! Failed.
    ECHO Printer name is invalid.
    GOTO SyntaxEnd
)
if %ERRORLEVEL% == 6 (
    ECHO !var! Failed.
    ECHO Windows updates are pending.
    GOTO SyntaxEnd
)

ECHO "%var%" error = %ERRORLEVEL%



:Syntax
ECHO.
ECHO silentinstall.cmd must be invoked from a command prompt using 'run as administrator'.
ECHO.
ECHO The silentinstall.cmd allows the unattended network or USB install of the XPS Card Printer Driver. 
ECHO The command allows you to print a sample card and start the Printer Dashboard as part of a network or USB install. 
ECHO You also use the command to install driver support files.
ECHO Note: You cannot perform both a network and a usb connection using a single command.
ECHO. 
ECHO Network Install Examples:
ECHO.
ECHO silentinstall.cmd network
ECHO Installs the Card Printer Driver at IP address 0.0.0.0.
ECHO Cannot use DisplayDashboard or PrintSampleCard with this command.
ECHO.
ECHO silentinstall.cmd network 123.45.6.789  
ECHO Installs the Card Printer Driver at IP address 123.45.6.789. 
ECHO.
ECHO silentinstall.cmd network 123.45.6.789 DisplayDashboard 
ECHO Installs the Card Printer Driver at IP address 123.45.6.789 and displays the Printer Dashboard.
ECHO.
ECHO silentinstall.cmd network 123.45.6.789  PrintSampleCard   
ECHO Installs the Card Printer Driver at IP address 123.45.6.789 and prints a driver sample card to the newly installed printer. 
ECHO.
ECHO silentinstall.cmd network 123.45.6.789  PrintSampleCard DisplayDashboard  
ECHO Installs the Card Printer Driver at IP address 123.45.6.789, prints a driver sample card to the newly installed printer, and displays the Printer Dashboard. 
ECHO.
ECHO USB Install Examples:
ECHO.
ECHO silentinstall.cmd usb   
ECHO Installs the Card Printer Driver using a USB connection. CAUTION: Do not plug in the USB cable until instructed. Plug in the USB cable when prompted. 
ECHO.
ECHO silentinstall.cmd usb DisplayDashboard 
ECHO Installs the Card Printer Driver using a USB connection and displays the Printer Dashboard.
ECHO.
ECHO silentinstall.cmd usb  PrintSampleCard   
ECHO Installs the Card Printer Driver using a USB connection and prints a driver sample card to the newly installed printer. 
ECHO.
ECHO silentinstall.cmd usb  PrintSampleCard DisplayDashboard  
ECHO Installs the Card Printer Driver using a USB connection, prints a driver sample card to the newly installed, and displays the Printer Dashboard. 
ECHO.
ECHO Install Support Files:
ECHO Use the silentinstall.cmd to install a driver support file. 
ECHO Some support files are not installed automatically when the driver is installed, or copied to a shared client when installing the driver on a client system. 
ECHO Specify one of the following:
ECHO.
ECHO Examples:
ECHO silentinstall.cmd MagstripeFonts
ECHO Installs magnetic stripe fonts on a shared printer client PC if it processes magnetic stripe cards using magnetic stripe fonts. 
ECHO.
ECHO silentinstall.cmd CustomMaskingBitmaps 
ECHO Installs bitmap files on a shared printer client. Modify the files to create user-defined bitmaps for print blocking or erase areas.
ECHO.
ECHO silentinstall.cmd LegacyMagstripeFonts 
ECHO Installs magnetic stripe fonts used by older generation desktop printers. Use this option to install the legacy fonts on a local or client system.
ECHO.
:SyntaxEnd
