Link to home
Start Free TrialLog in
Avatar of education-dynamics
education-dynamicsFlag for United States of America

asked on

VB script remove network printers wild card

Hi Expert People,

I have a remove network printer script here, but I have about 30 different printer names. Anyone know how to write a wild card to replace the printername.

Set objNetwork = CreateObject("Wscript.Network")
objNetwork.RemovePrinterConnection "\\servername\printername"

Or maybe something like this:

Printername = printer1
printername = printer2
printername = printer3
and so on...

Thank you for all your help!

Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Are these printers on the same network or on a different subnet or what ? if you could be more specific that would help.

We could make an array of printers and make it remove each printer that is stored in the array.
ASKER CERTIFIED SOLUTION
Avatar of tactonic_grate
tactonic_grate

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Set WshNetwork = CreateObject("WScript.Network")

rem ** This will delete existing printers **
On Error Resume Next
Set oPrinters = WshNetwork.EnumPrinterConnections
        For i = 1 to oPrinters.Count - 1 Step 2
               WshNetwork.RemovePrinterConnection oPrinters.Item(i)
Next

'The above will just remove any installed printers.

If you need anything else please post back.
Avatar of education-dynamics

ASKER

I don't know what arrays are but I have printers such as these listed below. Any script that would add all these under one script that would be great!

The shorter the script the better--it's just more cleaner and easier to understand.

\\svrprinter1\LA-2200
\\svrprinter1\palm1-2200
\\svrprinter1\accounting-2200
\\svrprinter1\hr-2200


I apologize for the response.