如何使用命令批量删除网络打印机

jamphevos 2010-01-21 07:47:38
1、操作系统为Windows 2003 sp2 简体中文版
2、有多台本地打印机及远程接入时连过来的多台网络打印机
3、windows有命令rundll32 printui.dll,PrintUIEntry 可以用来添加或删除打印机等操作
4、如何使用第3点的命令删除未知打印机名称的网络打印机(一次性批量或者枚举逐个删除也行)

备注:查了很久, 没找到办法不指定打印机名, 因为打印机名为未知的,最好不使用第三方软件,若有第三方软件可以实现定时删除网络打印机(本地打印机不需要删除)也行。
可以命令行键入命令查看帮助:rundll32 printui.dll,PrintUIEntry /?
...全文
4433 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
smallpigs520 2010-10-21
  • 打赏
  • 举报
回复
好傷心,執行了一下,把我電腦上的打印機都給刪了,還有我的PDF文檔轉換也沒了!
凄清浅醉还醒 2010-10-19
  • 打赏
  • 举报
回复
这个一定要顶..正需要.一楼的正解.二楼的也可以
就是just4 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jamphevos 的回复:]
#1楼的回复试过一次, 把所有的打印机全删除了,无论是本地还是网络的, 我只需要删除网络打印机,
[/Quote]

楼主真是对rundll32 printui.dll,PrintUIEntry用法熟悉,对批处理熟悉,就不会有这种提问了,/dl就是删除本地,/dn就是删除网络,把1楼的改一下不就是你需要的了,网友给出方案,适合自己的也要动动脑子修改下
jklcp 2010-01-22
  • 打赏
  • 举报
回复
学习
xman_78tom 2010-01-22
  • 打赏
  • 举报
回复
wmic printer where network=true 可以获得所有的网络打印机。

其实,何必麻烦。在 windows 2003 和 xp 中系统内置了 prnmngr.vbs 脚本,可以删除打印机。
ljc007 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jamphevos 的回复:]
#1楼的回复试过一次, 把所有的打印机全删除了,无论是本地还是网络的, 我只需要删除网络打印机,
[/Quote]

wmic path win32_printer get * /format:csv

你把所有信息全部贴出来,让1楼帮你看看能否排除本地打印机。
jamphevos 2010-01-22
  • 打赏
  • 举报
回复
#1楼的回复试过一次, 把所有的打印机全删除了,无论是本地还是网络的, 我只需要删除网络打印机,
#2楼的可以删除网络打印机,保留本地打印机,我在vista下测试,暂未到windows2003下测试. 应该是没问题,但还需要更多验证,看有没有其它问题. 谢谢大家的解答!
xman_78tom 2010-01-21
  • 打赏
  • 举报
回复
按下面的脚本创建 delprn.vbs 文件,在命令行中运行此脚本文件 cscript delprn.vbs

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
if objPrinter.Network = true then
objPrinter.Delete_
end if
Next
就是just4 2010-01-21
  • 打赏
  • 举报
回复
终于弄好了:
[code=BatchFile]@echo off
echo 开始删除所有打印机
for /f "skip=2 tokens=1,2* delims=," %%i in ('wmic path win32_printer get name /format:csv 2^>nul') do call :func %%j
echo.
echo 删除完成!!!
pause>nul
goto :end

:func
set pn=%*
if "%pn:~0,2%"=="\\" (rundll32 printui.dll,PrintUIEntry /n"%pn%" /dn /q) else (rundll32 printui.dll,PrintUIEntry /n"%pn%" /dl /q)
goto :end

:end[/code]
用法: rundll32 printui.dll,PrintUIEntry [options] [@commandfile] /a[file] 二进制文件名 /b[name] 基本打印机名 /c[name] 如果操作在远程机器上,unc 机器名 /dl 删除本地打印机 /dn 删除网络打印机连接 /dd 删除打印机驱动程序 /e 显示打印首选项 /f[file] inf 文件或输出文件 /ga 添加每个机器打印机连接 /ge 枚举每个机器打印机连接 /gd 删除每个机器打印机连接 /h[arch] 下列驱动程序体系结构之一,Alpha | Intel | IA64 | x64 /ia 用 inf 文件安装打印机驱动程序 /id 用添加打印机驱动程序向导安装打印机驱动程序 /if 用 inf 文件安装打印机 /ii 用带 inf 文件的添加打印机向导安装打印机 /il 用添加打印机向导安装打印机 /in 添加网络打印机连接 /j[provider] 打印提供程序名称 /k 将测试页打印到指定的打印机,不能安装打印机时的命令组合 /l[path] 打印机驱动程序源路径 /m[model] 打印机驱动程序型号名 /n[name] 打印机名 /o 显示打印机队列查看 /p 显示打印机属性 /q 安静模式,不显示错误信息 /r[port] 端口名 /s 显示服务器属性 /Ss 将打印机设置存到一个文件 /Sr 从一个文件还原打印机设置 储存或还原必须放在命令结尾的打印机设置选项标志: 2 PRINTER_INFO_2 7 PRINTER_INFO_7 c 颜色配置文件 d 打印机数据 s 安全描述符 g 全局 DevMode m 最低设置 u 用户 DevMode r 解决名称冲突 f 强制使用名称 p 解析端口 /u 如果已安装,则使用现有的打印机驱动程序 /t[#] 起始的以零为基础的索引页 /v[version] 驱动程序版本属于下列中的一个: Windows 95、98 和 ME | Windows NT 4.0 | Windows NT 4.0 或 2000 | Windows 2000 或 XP| Windows XP /w 如果指定的驱动程序不在 inf 中,则提示用户 /y 将打印机设为默认打印机 /Xg 获得打印机设置 /Xs 设定打印机设置 /z 不要自动共享这台打印机 /Z 不要自动生成打印机名 /K 更改 /v 和 /h 的意义来将 Windows x64 和 Windows IA64 | Windows NT x86 | Windows NT Alpha_AXP | Windows 4.0 分别接受为 0、1、2、3 /Z 共享这台打印机,只能跟 /if 选项一起使用 /? 帮助信息 @[file] 命令行参数文件 /Mw[message] 确认命令之前显示警告消息 /Mq[message] 确认命令之前显示确认消息 /W[flags] 指定向导(APW 和 APDW)的标志和切换 r 使向导可以从上一页重新启动 /G[flags] 指定全局标志和切换 w 抑制安装程序驱动程序警告 UI (超级静声模式) 例如: 运行服务器属性: rundll32 printui .dll ,PrintUIEntry /s /t1 /n\\machine 运行打印机属性: rundll32 printui .dll ,PrintUIEntry /p /n\\machine\printer 在本地运行添加打印机向导: rundll32 printui .dll ,PrintUIEntry /il 在 \\machine: rundll32 printui .dll ,PrintUIEntry /il /c\\Machine 运行添加打印机向导 运行队列查看: rundll32 printui .dll ,PrintUIEntry /o /n\\machine\printer 运行 inf 安装: rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "AGFA-AccuSet v52.3" 使用 inf 运行添加打印机向导: rundll32printui.dll,PrintUIEntry/ii/%windir%\inf\ntprint.in 添加每个机器打印机连接: rundll32 printui.dll,PrintUIEntry /ga /c\\machine /n\\machine\printer /j"LanMan Print Services" 删除每个机器打印机连接: rundll32 printui.dll,PrintUIEntry /gd /c\\machine /n\\machine\printer 枚举每个机器打印机连接: rundll32 printui.dll,PrintUIEntry /ge /c\\machine 用 inf 添加打印机驱动程序: rundll32 printui.dll,PrintUIEntry /ia /c\\machine /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000 或 XP" /f %windir%\inf\ntprint.inf 用 inf 添加打印机驱动程序: rundll32 printui.dll,PrintUIEntry /ia /K /c\\machine /m "AGFA-AccuSet v52.3" /h "Windows NT x86" /v 3 删除打印机驱动程序: rundll32 printui.dll,PrintUIEntry /dd /c\\machine /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000 或 XP" 删除打印机驱动程序: rundll32 printui.dll,PrintUIEntry /dd /K /c\\machine /m "AGFA-AccuSet v52.3" /h "Windows NT x86" /v 3 将打印机设为默认打印机: rundll32 printui.dll,PrintUIEntry /y /n "printer" 设置打印机注解: rundll32 printui.dll,PrintUIEntry /Xs /n "printer" comment "My Cool Printer" 取得打印机设置: rundll32 printui.dll,PrintUIEntry /Xg /n "printer" 取得文件中的打印机设置保存结果: rundll32 printui.dll,PrintUIEntry /f "results.txt" /Xg /n "printer" 设置打印机设置命令使用: rundll32printui.dll,PrintUIEntry/Xs/n"printer"? 将所有打印机设置存入一个文件: rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat" 从一个文件还原所有打印机设置: rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" 将二级打印机信息存入一个文件: rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat" 2 从一个文件还原打印机安全描述符: rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" s 从一个文件还原打印机全局 devmode 和打印机数据: rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" g d 从文件最少设置还原并分析端口名: rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" m p

6,868

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧