Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing All Network Printers

Status
Not open for further replies.

djlax152

IS-IT--Management
Jun 20, 2003
18
0
0
US
I need a Script that will remove all Network Printers stored on local machine. I have tried several that i found online and i can not get any of them to work! I want to inculde this small script before I map my printers so that they do not get messed up when my users see 5 printers.
 
just call the PRINTUI.DLL and use the /dl (delete) switch in your script for each printer found. I would think that would be the most stable way to do it. could be wrong though

 
Only problem is that i do not want to delete the local printers only the nework printers I am not sure how to use PRINTUI.dll
 
'Remove All Network Printers



Set WSHPritners = WSHNetwork.EnumPrinterConnections
For Loop_Counter = 0 To WSHPrinters.Count - 1 Step 2

If Left(WSHPrinters.Item(Loop_counter + 1),2) = "\\" then
WSHNetwork.RemovePrinterConnection WSHPrinter.Items(Loop_Counter +1),True,T
End If
Next

this is the script that i got so far but i keep getting an error

Line 5
Char 1
Object Required: 'WSHNetwork'
code 800a01a8
 
looks like you just have a few typos there.

also, are you creating the network object?
e.g
Code:
Set WSHNetwork = WScript.CreateObject("WScript.Network")

typos...

Items --> Item

WSHPritners --> WSHPrinters


 
also WSHPrinter.Items

Good practice to read your code very carfully for the first troubleshooting task. Typos are the first thing that will break it

 
For those of you that are still curious about this script. This one really works. I only tested this on windows XP though not sure about 2000

'----------------------------------------------------
'Remove all Network printers but not local printers
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections

For i = 0 to Printers.Count - 1 Step 2

If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
WScript.Echo Printers.Item(i+1)
WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
End IF
Next
 
Looks familiar... :) faq329-5798

I hope you find this post helpful.

Regards,

Mark
 
For windows XP use this script:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = TRUE")

For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

For Windows 2000, you have to manually remove each network printers:

Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\PrintServer\xerox3006"

You need to know the printer server name and pritner share name.

Hope this help.
Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top