Jump to content

Script to delete all network printers at logoff?


Recommended Posts

Posted

Anyone know of simple script to delete all Network printers (not local ones) at logoff. We run a script to add a printer based on machine name but when we occasionally swap a printer in a room and update the script, the old printer driver is left over and these can build up over time.

 

Thanks

Posted

Paste the following into notepad:

 

Option Explicit

Dim DelPrint, UNCpath

UNCpath = "\\%SERVER%\%PRINTER%"

On Error Resume next

Set DelPrint = WScript.CreateObject("WScript.Network")

DelPrint.RemovePrinterConnection UNCpath, true, true

WScript.Quit

 

Change the UNCpath to point to your printer.

 

Save it as a .vbs file and volia

Posted

This is based on the portname from the print server. It removes all printers that end in .local and .school. Not sure if it works, I've taken it from a bigger script

 

Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set WS_PRINTERS = WshNetwork.EnumPrinterConnections

For LOOP_COUNTER = 0 To WS_PRINTERS.Count - 1 Step 2

IF Lcase(right(WS_PRINTERS.Item(LOOP_COUNTER),6)) = "school" THEN

WshNetwork.removeprinterconnection WS_PRINTERS(LOOP_COUNTER+1), true

End If

IF Lcase(right(WS_PRINTERS.Item(LOOP_COUNTER),5)) = "local" THEN

WshNetwork.removeprinterconnection WS_PRINTERS(LOOP_COUNTER+1), true

End If

Next

Set WS_PRINTERS = Nothing

Posted

you could just cheat and use con2prt and run:

 

\\Server\Share\Con2Prt.exe /F

 

This will remove all network (but not local) printers

 

(yes i know its an NT4 tool, but it works perfectly here and does not require big VBS scripts, why reinvent the wheel?)

  • 2 weeks later...
Posted
you could just cheat and use con2prt and run:

 

\\Server\Share\Con2Prt.exe /F

 

This will remove all network (but not local) printers

 

(yes i know its an NT4 tool, but it works perfectly here and does not require big VBS scripts, why reinvent the wheel?)

 

I agree, con2prt works great for me, and adprintX is even better, i dont have a preference...

 

http://www.henrymellish.com/adprintx.zip

 

 

sorry DMccoy, advertising again.. I work for Microsoft :p

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