首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows批处理:使用rundll32处理错误

Windows批处理:使用rundll32处理错误
EN

Stack Overflow用户
提问于 2014-07-08 19:11:40
回答 1查看 1.3K关注 0票数 0

我试图从用户的打印机和设备中删除打印机。为了确保删除打印机,我有一系列if语句来删除网络上或本地上的打印机,并通过名称或名称+服务器连接删除打印机。

我的问题是,当我测试正在删除的打印机的成功与否时,无论打印机是否成功删除,errorlevel总是报告为0

有人知道用rundll32 printui.dll,PrintUIEntry处理错误的方法吗?

代码语言:javascript
复制
rundll32 printui.dll,PrintUIEntry /dn /n "%printerName%"
if %ERRORLEVEL% NEQ 0 goto first else (goto after)

:first
rundll32 printui.dll,PrintUIEntry /dl /n "%printerName%"
if %ERRORLEVEL% NEQ 0 goto second else (goto after)

:second
rundll32 printui.dll PrintUIEntry /dl /n \\DC1\%printerName%
if %ERRORLEVEL% NEQ 0 goto third else (goto after)

:third
rundll32 printui.dll PrintUIEntry /dn /n \\DC1\%printerName%
goto after

:after
ECHO If printer was not deleted, click on the 'start' menu button, go to 'Devices and Printers', right click on the printer you want to remove, and select 'Remove Device'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-08 22:16:11

因此,rundll32不设置errorlevel,因此,与其通过if语句删除正确的打印机,我只是删除了与下面代码的所有打印机连接。此代码不进行错误处理,但如果有必要,则可以。

代码语言:javascript
复制
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -xc

这个批处理脚本无论如何都是为了修复网络打印机的配置,所以我没有尝试删除本地连接的打印机。这里是我的整个脚本,以删除和添加网络打印机,以防有人想看。

代码语言:javascript
复制
@ECHO off

ECHO To solve your printer configuration problem, we will first remove the printers having the problem.
pause

REM remove all printer connections
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -xc
if %ERRORLEVEL% GTR 0 (ECHO If printer was not deleted, click on the 'start' menu button, go to 'Devices and Printers', right click on the printer you want to remove, and select 'Remove Device') else (goto end)

:end
ECHO Continue to printer installation?

pause

REM install printers
start \\DC1\LaserP2055
start \\DC1\LexmarkX544
ECHo The network printers LaserP2055 and LexmarkX544 have been installed
ECHO Would you like to exit the program?
pause
exit   
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24639899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档