user2882999
user2882999

Reputation: 23

if then statements in Windows batch

I was using the following script to remove a specific local printer on user logout:

RUNDLL32 printui.dll,PrintUIEntry /n "DYMO LabelWriter 450" /dl

How could this be modified so that if the printer does not exist locally, the script terminates without throwing an error?

Upvotes: 2

Views: 112

Answers (1)

npocmaka
npocmaka

Reputation: 57332

wmic printer get name /value | find "DYMO LabelWriter 450" && (
   RUNDLL32 printui.dll,PrintUIEntry /n "DYMO LabelWriter 450" /dl
)

This uses conditional execution

Or simply

WMIC /INTERACTIVE:ON PRINTER where Name="DYMO LabelWriter 450" DELETE >nul 2>&1

, but this should be ran as administrator

Upvotes: 2

Related Questions