我们的征途是星辰大海

My Conquest Is the Sea of Stars

batch-script-add-network-printer

继上次做过批处理脚本删除打印机后,上周在思考如何通过批处理脚本添加打印机,折腾了一番现有打印机配置为dat格式后,导出并导入,发现并不能用,再google一番,发现微软有了一套vbs脚本就是干这个事的,存放位置就在 “%WINDIR%\System32\Printing_Admin_Scripts\zh-CN\” 这里,参考来源如下

https://community.spiceworks.com/how_to/71708-how-to-install-printer-driver-and-add-a-network-printer-from-the-command-line

简单来说,就是说分3段来处理添加打印机的过程,1,配置打印机驱动,2,配置打印机端口,3,添加打印机

中午进行了测试,一条条添加几台打印机,发现效果不错,感觉上比一步步添加打印机要快不少,至少省事多了,效果过程图如下:

《batch-script-add-network-printer》

实际代码如下,供参考:

@echo off
::============================================================================================================================
:: 设置脚本的标题;颜色 [Background][Text] in hex (0 to F)
title 按需添加各楼层多余打印机 "wanjie" [2019-09-03]
color FC

:MENU
ECHO.
ECHO.=-=-=-=-=添加各楼层打印机 Powered by Wanjie=-=-=-=-=
ECHO.
ECHO           1:添加39楼打印机
ECHO           2:添加41楼打印机
ECHO           3:添加42楼打印机
ECHO           4:添加43楼打印机
ECHO           5:查看现有打印机
ECHO           6:退出
ECHO.
ECHO. 
ECHO.
echo.  请输入选择楼层的序号后回车:
set /p  M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
IF %M%==1 GOTO Add39

IF %M%==2 goto Add41

IF %M%==3 goto Add42

IF %M%==4 goto Add43

IF %M%==5 goto ListPrint

IF "%M%"=="6"exit

PAUSE

:Add39
color 08
echo. 执行命令1-添加39楼夏普--SHARP [email protected]

Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.7.4 -h 10.17.7.4
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "SHARP MX-M5608N PCL6" -h "\\10.17.36.6\打印机驱动\SHARP-5608\sharp_pcl6_ss0e_1606\x64" -i "\\10.17.36.6\打印机驱动\SHARP-5608\sharp_pcl6_ss0e_1606\x64\ss0emchs.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "SHARP [email protected]" -m "SHARP MX-M5608N PCL6" -r "IP_10.17.7.4"
echo; 39楼夏普打印机添加完毕,请试用,记得设置用户密码:)
goto MENU

:Add41
color 09
echo 执行命令2-添加41楼打印机--SHARP [email protected]
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.7.5 -h 10.17.7.5
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "SHARP MX-M503N PCL6" -h "\\10.17.36.6\打印机驱动\夏普 MX-M503N\printer-win10\printer\MX-Mono3_PCL_PS_1302a_ChineseS_Win8Server2012\Chinese1\PCL6\64bit" -i "\\10.17.36.6\打印机驱动\夏普 MX-M503N\printer-win10\printer\MX-Mono3_PCL_PS_1302a_ChineseS_Win8Server2012\Chinese1\PCL6\64bit\sr0emchs.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "SHARP [email protected]" -m "SHARP MX-M503N PCL6" -r "IP_10.17.7.5"
echo; 41楼夏普打印机添加完毕,请试用,记得设置用户密码:)
GOTO MENU

:Add42
color 0A
echo. 执行命令3-添加42楼夏普--SHARP [email protected]

Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.7.2 -h 10.17.7.2
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "SHARP MX-M5608N PCL6" -h "\\10.17.36.6\打印机驱动\SHARP-5608\sharp_pcl6_ss0e_1606\x64" -i "\\10.17.36.6\打印机驱动\SHARP-5608\sharp_pcl6_ss0e_1606\x64\ss0emchs.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "SHARP [email protected]" -m "SHARP MX-M5608N PCL6" -r "IP_10.17.7.2"
echo; 39楼夏普打印机添加完毕,请试用,记得设置用户密码:)

echo. 执行命令3-添加42楼佳能--Canon [email protected]茶水间左

Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.34.198 -h 10.17.34.198
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "Canon LBP6670 UFR II" -h "\\10.17.36.6\打印机驱动\6670\win64\Driver" -i "\\10.17.36.6\打印机驱动\6670\win64\Driver\CNLB0CA64.INF"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "Canon [email protected]茶水间左" -m "Canon LBP6670 UFR II" -r "IP_10.17.34.198"
echo; 42楼佳能--Canon [email protected]茶水间左打印机添加完毕,请试用

echo. 执行命令3-添加42楼佳能--Canon [email protected]楼茶水间中

Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.39.127 -h 10.17.39.127
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "Canon LBP6650/3470 UFR II" -h "\\10.17.36.6\打印机驱动\6670\win64\Driver" -i "\\10.17.36.6\打印机驱动\6670\win64\Driver\CNLB0CA64.INF"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "Canon [email protected]楼茶水间中" -m "Canon LBP6670 UFR II" -r "IP_10.17.39.127"
echo; Canon [email protected]楼茶水间中-打印机添加完毕,请试用:)

GOTO MENU


:Add43
color 09
echo 执行命令4-添加43楼夏普打印机--SHARP [email protected]
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.7.3 -h 10.17.7.3
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "SHARP MX-M503N PCL6" -h "\\10.17.36.6\打印机驱动\夏普 MX-M503N\printer-win10\printer\MX-Mono3_PCL_PS_1302a_ChineseS_Win8Server2012\Chinese1\PCL6\64bit" -i "\\10.17.36.6\打印机驱动\夏普 MX-M503N\printer-win10\printer\MX-Mono3_PCL_PS_1302a_ChineseS_Win8Server2012\Chinese1\PCL6\64bit\sr0emchs.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "SHARP [email protected]" -m "SHARP MX-M503N PCL6" -r "IP_10.17.7.3"
echo; 43楼夏普打印机添加完毕,请试用,记得设置用户密码:)


echo 执行命令4-添加43楼惠普--HP577彩色@老师边上
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.33.205 -h 10.17.33.205
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "HP Universal Printing PCL 6" -h "\\10.17.36.6\打印机驱动\HP577" -i "\\10.17.36.6\打印机驱动\HP577\hpcu220u.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "HP577彩色@老师边上" -m "HP Universal Printing PCL 6" -r "IP_10.17.33.205"
echo; HP577彩色@老师边上添加完毕,请试用:)


echo 执行命令4-添加43楼惠普--HP577彩色@Room4320
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.34.203 -h 10.17.34.203
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "HP Universal Printing PCL 6" -h "\\10.17.36.6\打印机驱动\HP577" -i "\\10.17.36.6\打印机驱动\HP577\hpcu220u.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "HP577彩色@Room4320" -m "HP Universal Printing PCL 6" -r "IP_10.17.34.203"
echo; HP577彩色@Room4320添加完毕,请试用:)



echo 执行命令4-添加43楼惠普--HP4525彩色@F43前台后面房间
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.33.236 -h 10.17.33.236
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "HP Color LaserJet CP4520 Series PCL6" -h "\\10.17.36.6\打印机驱动\前台彩色打印机HP_CP4525_drv" -i "\\10.17.36.6\打印机驱动\前台彩色打印机HP_CP4525_drv\hpc4520u.inf"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "HP4525彩色@F43前台后面房间" -m "HP Color LaserJet CP4520 Series PCL6" -r "IP_10.17.33.236"
echo; -HP4525彩色@F43前台后面房间添加完毕,请试用:)


echo. 执行命令4-添加43楼佳能--Canon LBP6670黑白@Room4320

Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_10.17.34.210 -h 10.17.34.210
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prndrvr.vbs -a -m "Canon LBP6670 UFR II" -h "\\10.17.36.6\打印机驱动\6670\win64\Driver" -i "\\10.17.36.6\打印机驱动\6670\win64\Driver\CNLB0CA64.INF"
Cscript %WINDIR%\System32\Printing_Admin_Scripts\zh-CN\Prnmngr.vbs -a -p "Canon LBP6670黑白@Room4320" -m "Canon LBP6670 UFR II" -r "IP_10.17.34.210"
echo; 43楼佳能--Canon LBP6670黑白@Room4320打印机添加完毕,请试用

GOTO MENU

:ListPrint
color 0C
wmic printer get Name /value

:cmd6
echo 执行命令6-退出菜单

GOTO MENU

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据