script for printer installation automation

2

Good afternoon, I have in my environment a print server with a total of 63 printers installed and shared on the network, I would like a script to automate the installation of these printers on the machines of the company, so far I have done the script below in .bat, but it is only installing 1 printer, unless I repeat the code block 63 times to do with each one I wanted a way to automate it to install all printers on the print server (checking if they are installed before installing to not install more than 1 time) but I could not think of a syntax and I do not want to have to repeat this block of code 63 times

SET IMPRESSORA=\HOSTNAME_SERVIDOR\COLOR


wmic printer get name /value | findstr /I /E "%IMPRESSORA%"


IF NOT %ERRORLEVEL% == 0 Rundll32 printui.dll,PrintUIEntry /in /n %IMPRESSORA%
    
asked by anonymous 15.05.2018 / 21:24

3 answers

1

Just create a text file with the name impressoras.txt in the workspace and add in it the name of all printers one on each line:

example:

IMPRESSORA1
IMPRESSORA2
IMPRESSORA3
...

and modify IP-DO-SERVIDOR by the IP of the server where the printers are located. I did not test the script for not having a server with 63 printers installed, but I think it will work. the only problem is that you may need give OK in each of the printers' installations. you may have some Rundll32 parameter that leaves the installation silent. follow the script ...

    @echo off
    mode 90,20 
    setlocal enabledelayedexpansion

    for /f "tokens=* delims= " %%R in (%userprofile%\desktop\impressoras.txt) do (

    set impr=%%R

    wmic printer get name /value | findstr /I /E !impr!>nul

    if !errorlevel! EQU 0 (echo.impressora !impr! j  foi instalada) Else (

    echo.
    echo. INSTALANDO: !impr! ...
    Rundll32 printui.dll,PrintUIEntry /in /n \IP-DO-SERVIDOR\!impr!
    )
    )
    )
    
18.05.2018 / 03:25
1

So!

@echo off
set "$impressoras=impressora1 impressora2 impressora3 impressora4 impressora5"
set  "$server=\0.0.0.0.0"

for %%a in (%$impressoras%) do (
  echo Tratando =^> [%%a]
  wmic printer get name /value | findstr /I /E "%%a" && echo Impressora [%%a] ja instalada || (
  echo Instalando [%%a]
  Rundll32 printui.dll,PrintUIEntry /in /n %$server%\%%a
  )
)
    
17.05.2018 / 12:33
0

It would be good for you to create a VBS

Inside VBS you can loop like this:

Do While X > -1
  'Aqui dentro você executa os blocos que você já fez
  set objSh = CreateObject("WScript.Shell")
  objSh.Run "cmd /k Seus comandos", 0

  X = X - 1
Loop

Something like this should work for you, if you need to look for VBScript, common VBS.

    
15.05.2018 / 21:37