我试图从用户的打印机和设备中删除打印机。为了确保删除打印机,我有一系列if
语句来删除网络上或本地的打印机,并通过名称或名称以及服务器连接删除打印机。
我的问题是,当我测试移除打印机是否成功时,errorlevel
始终报告为0
,无论打印机是否未成功移除。
是否有人知道使用rundll32 printui.dll,PrintUIEntry
处理错误的方法?
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'
答案 0 :(得分:0)
因此rundll32
未设置errorlevel
,因此我只是删除了所有打印机连接,而不是通过if
语句来删除正确的打印机。此代码不进行错误处理,但如果有必要,可以进行错误处理。
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -xc
此批处理脚本无论如何都是为了修复网络打印机的配置,因此我没有尝试删除本地连接的打印机。这是我删除和添加网络打印机的整个脚本,以防有人想看。
@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