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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to remove network printers?

Status
Not open for further replies.

danomac

IS-IT--Management
Aug 2, 2002
731
AM
We have a bunch of ghost printers on our LAN. Due to recent changes around here a bunch of printers were retired, and now of course, the users have a bunch of "ghost" network printers installed.

So I got this idea... why don't I look for a script to only remove the networked printers (and not the ones physically attached to the machine, if any?)

Good idea, but I don't know where to start.

I know there is a method to enumerate installed printers, but I am not sure how to tell if it is a local or networked printer.

I'm sure someone has come across this problem before. (As it could be useful, disconnecting printers in a logoff script. Handy for making changes to the network. I already do this for mapped network drives.)

Any ideas? Or can someone point me in the right direction?

D
 
Do you have the script: prnmgr.vbs in your c:\winnt\system32 folder?

If not, if you have an XP machine on your network you will find it in the equivalent directory: c:\windows\system32

It will work find under Win2k. Start, Run, CMD
cscript prnmgr.vbs /?

Will show you the options. You can quickly clean out the printer drivers, including on a remote print server.
 
The following script should help you out:

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\PrintServer\?????"

Just replace the printserver and the ???? with the name of your networked printer.

You will have to do this as a local machine logoff script, and you will need to have each and every printer spelled out. You can, however, just have one script, just multiple entries....
 
Darn.

It seems that our only XP machine doesn't have that tool.
And it looks like it would do exactly what I want, of course. "prnmgr.vbs -xc", from what I've seen on web pages. None have a place to download it.

I think it's part of the Resource Kit of Windows 2003 Server... and we are running SBS 2000, so it isn't really feasible to purchase it, especially at it's cost, for one file.

I guess I'll have to try to write my own script.

This should be interesting.

Thx for the replies.

D
 
I used the following VBS script to remove printers at login time. Just call the script from in your login script like this:

wscript.exe //nologo //B \\server\PathToScripts\RemoveOldPrinter.vbs


************************

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where DriverName = 'Printer Driver Name Here'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next


************
You can get the driver name from the printer properties dialog. Worked like a charm for me. Hope it helps someone else.

-P
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top