我在服务器上有6个网络打印机,需要将它们移动到另一台服务器。我有95个客户端使用它们,但有些只安装了某些打印机。我需要对打印机进行批处理文件查询(如果存在),然后删除并重新添加到新服务器。这是迄今为止的脚本。我无法弄清楚查询语句。
@ 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
答案 0 :(得分:1)
这是应该生成所需输出的东西。这是prnmngr.vbs在Windows 7中的位置,我认为它位于XP的System32的根目录中。不管怎样,它应该删除旧的并立即添加新的。
@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
编辑以根据打印机名称匹配包含删除/添加功能。