script for printer installation automation

Asked

Viewed 2,628 times

3

Good afternoon guys, 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 for automating the installation of these printers on the company machines, so far I have done the script below in . bat, but it’s only installing 1 printer, unless I repeat the code block 63 times to make with each one I wanted a way to automate it to install all printers from the print server (checking if they are installed before installing to install no more than 1 time) but I could not think of a syntax and do not want to have to repeat this code block 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%
  • This "COLOR" is the name of a printer you used as a test in your Script?

  • 1

    this, is an example of one of the printers

3 answers

1

Thus !

@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
  )
)
  • but where I choose the server path in that script ?

  • I edited the answer !

  • Sachadee, he wants the script not to re-install a printer that may already be installed on any of the machines. he wants the script to install only those that are not installed, on each of the machines, you missed adding this in the Script

  • I modified the script now this ok ! : ) It was a type error !

1

It would be good for you to create a VBS

Inside the VBS you can make a loop like the below:

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 suit your case, if you need to search for Vbscript, VBS.

  • Where are the variavels defined ???? Isn’t a loop on top of int but rather of string ! X = X - 1 your loop will never work !!!

  • Only if you Setta it to 63 in the beginning ! :)

  • The variables you define outside the loop, I just gave an example of how it can be done, it wasn’t a complete thing. And the loop works rather being integer because I use it, is that in my case I use it set itself as X = 10 and then I go doing X = X -1, as I said is an example, change to what you need.

  • got yes ! this loop will work by bad numeric value in case the printers are not numbers but string !

1

Just create a text file with the name impressoras.txt in the Work area and add the name of all printers one in each row:

example:

IMPRESSORA1
IMPRESSORA2
IMPRESSORA3
...

and modify IP-DO-SERVIDOR by the IP address of the server where the printers are. I didn’t test the script for not having a server with 63 printers installed, but I think it’s gonna work. the only problem is that maybe you need to give a OK at each printer facility. may have some parameter of the Rundll32 to keep the installation quiet. follows 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!
    )
    )
    )
  • made some syntax errors, but I fixed it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.