I have 6 Network Printers on a server and need to move them to another server. I have 95 clients that use them but some only have certain printers installed. I need to have a batch file query for a printer, if it exist then remove and re-add it to the new server. Here is the script so far. I can't figure out the query statement.
@ Remove current printer from computer
Rundll32 PrintUI.DLL,PrintUIEntry /dn /q /n \\server6\Printer1
@ Add new Printer to computer
Rundll32 PrintUI.DLL,PrintUIEntry /in /q /n \\server11\Printer1
@ Remove current printer from computer
Rundll32 PrintUI.DLL,PrintUIEntry /dn /q /n \\server6\Printer2
@ Add new Printer to computer
Rundll32 PrintUI.DLL,PrintUIEntry /in /q /n \\server11\Printer2
Here is something that should generate the output you need. That is the location of the prnmngr.vbs in Windows 7, I think it's in the root of System32 in XP. either way, it should remove the old and add the new now.
@echo off
setlocal
cscript %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l > printers.txt
set count=0
FOR /F "tokens=1-3 delims= " %%G IN (printers.txt) DO call :loop %%G %%H %%I
:loop
if "%1"=="" goto :endloop
if "%1"=="Printer" (
if "%2"=="name" (
if "%3"=="\\server6\Printer1" (
echo Printer1
REM Remove current printer from computer
Rundll32 PrintUI.DLL,PrintUIEntry /dn /q /n \\server6\Printer1
REM Add new Printer to computer
Rundll32 PrintUI.DLL,PrintUIEntry /in /q /n \\server11\Printer1
)
if "%3"=="\\server6\Printer2" (
echo Printer2
REM Remove current printer from computer
Rundll32 PrintUI.DLL,PrintUIEntry /dn /q /n \\server6\Printer2
REM Add new Printer to computer
Rundll32 PrintUI.DLL,PrintUIEntry /in /q /n \\server11\Printer2
)
pause
)
)
SHIFT
goto :loop
:endloop
Edit made to include your Remove/Add functions based on printer name match.
The only reason I say that is because I know this code works on my machine and I have a XP VM I ran it on for kicks as well - iesou 2012-04-09 17:25