Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/8917946/batch-file-to-detect-if-local-printer-is-installed-and-to-do-stuff-if-it-isnt/63272735#63272735

@ECHO OFF

SET DUPSERVER=\\SERVER\PSHARE
FOR /F "tokens=1,2*" %%N IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" ^| find /I "%DUPSERVER%"') Do (
IF /I "%%N" == "%DUPSERVER%" (
ECHO FOUND
  SET FOUNDDUPSERVER=TRUE
  SET FOUNDPRINTER=TRUE
)
)
PAUSE
@ECHO OFF
@CLS

SET SERVER=%~1
::Functions::
::Check If printer Installed
:PRINTCHECK
SET SHARE=%~2
FOR /F "tokens=1,2*" %%N IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" ^| find /I "%SHARE%"') Do (
 IF /I "%%N" == "%SHARE%" (
  ECHO "%SHARE%" Printer Already Installed
  EXIT /B
 )
)
::ELSE 
ECHO Printer \\%SERVER%\%SHARE% NOT Installed
ECHO Installing Printer \\%SERVER%\%SHARE%
set PRINTUI=rundll32 printui.dll PrintUIEntry /q /in /ga /n
::%PRINTUI% "\\%SERVER%\%SHARE%"
ECHO "You Must Reboot to Complete Printer Installation"
PAUSE
EXIT

Test:

@ECHO OFF
CLS

set SERVER=
set SHARE=

CALL "printer_check.cmd" %SERVER% %SHARE%

PAUSE
  • No labels