Jump to content

Recommended Posts

Posted

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

Posted

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

Posted
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.
Posted

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.

'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).

Posted

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:

 

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.

Posted

Ok heres a script to delete more than multiple printers.

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...