Scripts Thread, delete printers in Coding and Web Development; hi all,
Here's the situation. We are moving away from a localy managed tcp/ip printers to a central print server, ...
-
14th June 2007, 07:54 AM #1 delete printers
hi all,
Here's the situation. We are moving away from a localy managed tcp/ip printers to a central print server, for printer usage monitoring.
I have used ric's script to add the networked printers to the computers at startup, but i want to save a bit of time and have it delete printers on tcp/ip ports, but keep printers on other ports. this is because we use cutepdf and we have a printer setup to print directly to reprographics, i also dont want to interfere with any printers that staff have setup on there laptops for home use.
So to sumerise i need some help with a vbscript to delete all printers on tcp/ip ports only.
Thanks for your help
-
-
IDG Tech News
-
14th June 2007, 08:07 AM #2 Re: delete printers
set wNet = createobject("wscript.network")
'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = WNet.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
'end delete existing printers
Ben
-
-
14th June 2007, 08:17 AM #3 Re: delete printers
Which script are you using again.. doesnt ric's script only removed network printers anyway?
-
-
14th June 2007, 08:58 AM #4 Re: delete printers
ric's script only removes network printers which are on a print server. i have network printers that go directly to the printer from the computer.
-
-
14th June 2007, 09:01 AM #5 Re: delete printers
Ok do you know the port names for the ones you want to delete?
Ben
-
-
14th June 2007, 09:09 AM #6 Re: delete printers
the port names should be "IP_ip of the printer"
which is just the standard that windows setsup.
-
-
14th June 2007, 09:34 AM #7 Re: delete printers
Odd, just had a quick look and it looks like ric's script removes anything except those that have "usb" or "lpt" in the port name. Maybe im looking at the wrong script but all you need to do is to edit plexer script or add to it.
Code:
'To remove only networked printers use this If Statement
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
This bit of code defines what to remove by using the port name ie it searches for "\\" so all you have to do is to copy the whole thing and change that value with something like "IP". Think thats about right (correct me if im wrong).
-
-
14th June 2007, 11:00 AM #8 Re: delete printers
i have tried the script, it runs through without errors but does not delete the printers.
-
-
14th June 2007, 01:28 PM #9 Re: delete printers
Right ok i think ive posted up a script to deal with your problem.. whats going on is that you have printers that are locally installed on you machines (right?) and the script wont get rid of it, which it souldnt do cause it tries to delete the network printer. There is a script to do it but it doesnt always work and you will need to reghack it to get rid. Here is the script to get rid of 1 local printer:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where DeviceID = 'HP LaserJet 1100")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next Ill sort out another script to get rid of locally installed network printers in a bit.
-
-
14th June 2007, 02:25 PM #10 Re: delete printers
Ok heres a script to delete more than multiple printers.
Code:
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Remove All Network Printers.
Set oPrinters = WshNetwork.EnumPrinterConnections
FOR Counter = 0 to oPrinters.Count - 1
IF mid(oPrinters.Item(Counter), 1, 2) = "IP" THEN
PrinterPath = oPrinters.Item(Counter + 1)
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where DeviceID = '" & PrinterPath & "'")
For Each Printer in colInstalledPrinters
Printer.Delete_
Next
End If
Next
-
-
14th June 2007, 02:46 PM #11 Re: delete printers
thanks for all your help. It has saved be about a weeks work going round manully deleting printer
-
-
14th June 2007, 02:54 PM #12 Re: delete printers
No Probs.. I assume it worked then
-
SHARE: 
Similar Threads
-
By Mr_M_Cox in forum Scripts
Replies: 13
Last Post: 22nd February 2013, 03:53 PM
-
By woody in forum Windows
Replies: 74
Last Post: 15th February 2013, 02:28 PM
-
By mac_shinobi in forum Scripts
Replies: 4
Last Post: 14th December 2007, 08:51 AM
-
By woody in forum Scripts
Replies: 7
Last Post: 27th November 2005, 10:41 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules