code in else statement not executing
Posted: 31 Dec 2023 13:02
Hi people,
I put this script together with the following logic:
IF driver.inf is found output 'printer driver found' ELSE IF device instance id is found output 'reader ID found' ELSE 'reader id not found'
The first portion of the script works fine however the script then outputs Echo Printer Driver not found..Looking for Reader... and skips straight to echo reader ID not found even though the reader is definately present. Not sure what I am doing wrong.
I put this script together with the following logic:
IF driver.inf is found output 'printer driver found' ELSE IF device instance id is found output 'reader ID found' ELSE 'reader id not found'
The first portion of the script works fine however the script then outputs Echo Printer Driver not found..Looking for Reader... and skips straight to echo reader ID not found even though the reader is definately present. Not sure what I am doing wrong.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "driverinf=magu.inf"
set "readerId=USB\VID_076B&PID_5320\OKCM0021111090337566741524390121"
REM Check if the printer driver exists in the output of pnputil
pnputil /enum-devices /connected /drivers /class Printer | findstr /C:"%driverinf%" >nul
REM If the printer driver is found, output 'printer found'
if %errorlevel% equ 0 (
Echo Printer Driver found..
) else (
Echo Printer Driver not found..Looking for Reader...
REM Check if the readerID exists in the output of pnputil
pnputil /enum-devices /connected | findstr /C:"%readerId%" >nul
REM If the device instance ID is found, output reader found
if %errorlevel% equ 0 (
echo Reader ID found...
) else (
echo reader ID not found.
)
)