RobC Posted January 25, 2006 Posted January 25, 2006 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.
ChrisH Posted January 25, 2006 Posted January 25, 2006 I will assume you have looked ar Rics script. I think with your setup its this line that needs changing 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.
_Rob_ Posted January 25, 2006 Posted January 25, 2006 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.
apeo Posted January 25, 2006 Posted January 25, 2006 Try this: 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
RobC Posted January 25, 2006 Author Posted January 25, 2006 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
apeo Posted January 25, 2006 Posted January 25, 2006 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
Ric_ Posted January 25, 2006 Posted January 25, 2006 I think you'll find that the script at http://edugeek.net/index.php?name=Forums&file=viewtopic&t=404 does this for you
apeo Posted January 25, 2006 Posted January 25, 2006 Man what was up with my last post.. loads of typos :oops: @Ric_: Yup, the section on your script that deletes printers did what i suggested.
RobC Posted January 25, 2006 Author Posted January 25, 2006 @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.
apeo Posted January 25, 2006 Posted January 25, 2006 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.
fooby Posted January 25, 2006 Posted January 25, 2006 con2prt /f Deletes all connections to network printers, leaves local ones alone. works for us here. http://www.ss64.com/nt/con2prt.html
apeo Posted January 25, 2006 Posted January 25, 2006 Problem is, it is a local printer but uses ip for port so con2prt wont work.
fooby Posted January 25, 2006 Posted January 25, 2006 Ah right I see. You are right, con2prt will ignore that then.
Ric_ Posted January 25, 2006 Posted January 25, 2006 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.
ajbritton Posted January 25, 2006 Posted January 25, 2006 Logon scripts run with elevated priviledges... Really? I thought they ran in the user security context. Is there any MS documentation on that?
RobC Posted January 26, 2006 Author Posted January 26, 2006 And the suggestions just keep coming! Well, I've cracked it using prnmngr.vbs & I'll just add back any LPT or USB connected printers manually (there's only a few anyway). On top of that, I've finally got my head round push installs using Lexmark's scripting system so I should soon be able to remove all of our extraneous printers & start again with just the required printers on each workstation. Although knowing my luck, it'll all go south when I try to actually run it! Cheers, RobC.
ken_kaniff Posted January 26, 2006 Posted January 26, 2006 no, you're right, they do run in the contect of the user who is logging on
Pear Posted March 7, 2006 Posted March 7, 2006 I'm stuck on is how to make so that the script will only run if the user logged on is either kid1, kid2 or kid3.
Pear Posted March 7, 2006 Posted March 7, 2006 sorry... usernames. There is apparently 3 kids who keep printing out reams but deny they are doing it and claim its other using their name. So I've been asked if they can be disabled from printing.
apeo Posted March 7, 2006 Posted March 7, 2006 what you could do is to have a the script check username and for those users not to install printers. Gimme a sec and i will see if i can come up with an example.
apeo Posted March 7, 2006 Posted March 7, 2006 Ok here is something you can look at and alter according to your needs.printers_935.vbs
Pear Posted March 7, 2006 Posted March 7, 2006 Cheers, I'll see if I can test it with some usernames after school.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now