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!

Deleting local printers in w2k

Status
Not open for further replies.

ccoll23

MIS
Jan 17, 2002
43
0
0
US
I have a script to delete printers on our workstations (they are network printers but were initially set up on Win 2000 workstations with a local port..\\server\printer).
I have figured out how to delete all printers on a workstation, but need to keep the printers connected to LPT1, so I have a script that will delete only the local ports I specify. It works great on our Win XP machines; however, it doesn't work on Win 2000.(line 20 char 5.."provider is not capable of the attempted operation"..80041024...swbemobject)...

Any thoughts?

Thanks

'this will delete printers setup with a local port (\\srh-nt4\mis)...replace "deviceID = '' with
'printer name from corresponding .txt file in \\srh-nt1\srhlogon$\unison\printers..Must also add full
'string for each printer to be deleted.
'*************************************************************************************************

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'HP LaserJet 4000 Series PCL 5'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'HP LaserJet 2100 (Copy 2)'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'HP LaserJet 2100'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
 
Take a look in my FAQ for how to delete the local printers.

faq329-5798

If that example does not do it for you I would check out those WIn2K boxes and make certain they have the WSH 5.6 Engine installed.

I hope you find this post helpful.

Regards,

Mark
 
I forgot to mention that the win 2000 boxes do have wsh 5.6..Also, your script is very informing and helpful, thanks, but I am not sure where it has an example of deleting local printers..

Thanks for your help
 
it take it the line it fails on is the .Delete method?
 
the .Delete method is directly supported by the win32_printer class, i guess it is therefore using the SWbemObject.Delete_ . the documentation of this method does say it depends on the provider supporting it, i guess it doesnt in w2k, surprising though, is wmi different on the 2 OS's?
 
The link states it deletes a "tcp/ip" port, I'm trying to delete a local port. Is there a different method or location for this? (the site also said w2k was not a supported platform).
Any other thoughts?

Much Appreciated!
 
net use /delete lpt1

might work if deleting ports?
 
The following code is taken from the printer section of my FAQ. You just needed to read the coments in green...

Note the following will remove ALL printers including local printers

Code:
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next

I hope you find this post helpful.

Regards,

Mark
 
Thanks for all the input, but I didn't use this one before because I don't want to delete the stand alone printers attached to LPT1 (just the printers that were set up with created local ports of \\server\printer.)

Thanks
 
can you get a list of printer ports, lpt1,2,3 and the corresponding server\printername, then marks suggestion to delete the ones you want?
you can use wmi to get the list and then WshNetwork to delete?
simply using .exec and "net use" will give you this info but i would opt for the code you have already posted on wmi but just use it to get the list...
 
OK, so again please refer back to the FAQ. I have code there that checks if the printer connection starts with "\\" and if do removes it.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top