Scripts Thread, Removing printers in Coding and Web Development; Ok, I need a script that will remove all printers from a workstation, EXCEPT where that printer is connected via ...
-
25th January 2006, 10:51 AM #1 Removing printers
Ok, I need a script that will remove all printers from a workstation, EXCEPT where that printer is connected via LPT or USB.
Basically, all of our network printers are connected directly to the network and so are installed on the PC as Local printers using a Standard TCP/IP Port. I now need to remove them as I need to do a bulk update of drivers and printer types (so many changes!). I've tried variations of the scripts I've found on here, but none seem to actually work. Anyone know how to do what I'm after?
And no, I can't run them all through a server or use logon scripts (don't you just love managed services!).
Cheers all,
Rob Cowan.
-
-
IDG Tech News
-
25th January 2006, 11:08 AM #2 Re: Removing printers
I will assume you have looked ar Rics script.
I think with your setup its this line that needs changing
Code:
For i = 0 to oPrinters.Count - 1 Step 2
Its something to do with the step that handles those direct printers because when I log onto the print server my log in script does not delete all the printers. Try it without the step 2 or look at con2prt.
-
-
25th January 2006, 12:02 PM #3
- Rep Power
- 0
Re: Removing printers
Why not just disconnect all printers and then reconnect the relevant ones depending on the computer and its location? Might make things easier in the long run.
Rob.
-
-
25th January 2006, 12:10 PM #4 Re: Removing printers
Try this:
Code:
on error resume next
Set shell= WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
dim Counter, PrinterPath
'Remove All Network Printers.
Set oPrinters = WshNetwork.EnumPrinterConnections
FOR Counter = 0 to oPrinters.Count - 1
IF mid(oPrinters.Item(Counter), 1, 2) = "\\" THEN
PrinterPath = oPrinters.Item(Counter)
WshNetwork.RemovePrinterConnection PrinterPath, True, True
End If
Next
-
-
25th January 2006, 12:57 PM #5 Re: Removing printers
Ok. I've found a solution of sorts. I'm now using the Prnmngr.vbs script that appears to come with Windows XP.
@Chris: Cheers for the pointer. I might look down that route if I ever get more time/vbscript skills.
@_Rob_: Was trying to avoid this but I think it's going to have to be the way.
@apeo: Unfortunately, I've already tried that script. I'm not 100% sure, but I think it's actually looking for the beginnings of a UNC path in the printer settings, which these won't have as they're running direct to an IP address.
Either way, thanks for the responses. And if anyone's interested in it, you can find out more about Prnmngr.vbs here
-
-
25th January 2006, 01:56 PM #6 Re: Removing printers
Oh right you have printers installed locally using IP. Yes your are right is is looking for the first 2 chars of unc path so in your case i probably would have deleted all printers that ltp: or usb: ie if not ltp: then but as you have alredy foud a way it doesnt really matter
-
-
25th January 2006, 02:29 PM #7 Re: Removing printers
I think you'll find that the script at http://edugeek.net/index.php?name=Fo...iewtopic&t=404 does this for you
-
-
25th January 2006, 03:00 PM #8 Re: Removing printers
Man what was up with my last post.. loads of typos
ops:
@Ric_: Yup, the section on your script that deletes printers did what i suggested.
-
-
25th January 2006, 03:49 PM #9 Re: Removing printers
@Ric: Nope, tried that one too. It's entirely possible that these PCs are just doing this to annoy me. Also, I'm not running the script as a logon script. It's actually being punted out using the Ghost Console which then executes the command on each system locally (or that's the theory anyway!). I would love to use it as a logon script, but I have no control over those.
-
-
25th January 2006, 04:16 PM #10 Re: Removing printers
Just checked it out and i think its case sensitive so lpt should be LPT. Oh thanks for letting us know about the Prnmngr.vbs, may come it handy at some point in the future.
-
-
25th January 2006, 04:26 PM #11 Re: Removing printers
con2prt /f
Deletes all connections to network printers, leaves local ones alone. works for us here.
http://www.ss64.com/nt/con2prt.html
-
-
25th January 2006, 05:04 PM #12 Re: Removing printers
Problem is, it is a local printer but uses ip for port so con2prt wont work.
-
-
25th January 2006, 05:05 PM #13 Re: Removing printers
Ah right I see. You are right, con2prt will ignore that then.
-
-
25th January 2006, 05:31 PM #14 Re: Removing printers
What context does your script get run as? Logon scripts run with elevated priviledges and if that doesn't work, run it as a startup script cos then it will run as SYSTEM.
-
-
25th January 2006, 05:36 PM #15 Re: Removing printers

Originally Posted by
Ric_ Logon scripts run with elevated priviledges...
Really? I thought they ran in the user security context. Is there any MS documentation on that?
-
SHARE:
Similar Threads
-
By alan-d in forum Windows
Replies: 17
Last Post: 7th September 2009, 02:09 PM
-
By faza in forum Networks
Replies: 3
Last Post: 11th October 2007, 07:56 AM
-
By _Bat_ in forum Windows
Replies: 12
Last Post: 3rd May 2007, 04:27 PM
-
Replies: 7
Last Post: 21st September 2006, 01:54 PM
-
By wesleyw in forum How do you do....it?
Replies: 2
Last Post: 22nd August 2006, 10:01 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