Little-Miss Posted June 28, 2010 Posted June 28, 2010 Morning, I currently have a VB script that maps all the printers when people logon. Now i'm having a problem with my staff one. After a bit of fiddling I have managed to get a long neglected printer working in the staff room, but unfortunately it is appearing twice on their printer list. The working one is Staff-Room but its also bringing up Staff Room which throws up an error message. The script is in this format... if left(compname,4) = "INFS" then PrinterPath = "\\curricsvr1\JUNIOR-SUITE" PrinterPath2 = "\\curricsvr1\INFANT-SUITE" PrinterPath3 = "\\curricsvr1\FOUNDATION" PrinterPath4 = "\\curricsvr1\INFANT-LIBRARY" PrinterPath5 = "\\curricsvr1\STAFF-ROOM" WshNetwork.AddwindowsPrinterConnection PrinterPath WshNetwork.AddwindowsPrinterConnection PrinterPath2 WshNetwork.AddwindowsPrinterConnection PrinterPath3 WshNetwork.AddwindowsPrinterConnection PrinterPath4 WshNetwork.AddwindowsPrinterConnection PrinterPath5 WshNetwork.SetDefaultPrinter "\\curricsvr1\INFANT-SUITE" end if
ted_baker Posted June 28, 2010 Posted June 28, 2010 I delete all printers first, then add them: Set WshNetwork = CreateObject("WScript.Network") On Error Resume Next Set oPrinters = WshNetwork.EnumPrinterConnections For i = 1 to oPrinters.Count - 1 Step 2 WshNetwork.RemovePrinterConnection oPrinters.Item(i) Next Set WshNetwork = CreateObject("WScript.Network") WshNetwork.AddWindowsPrinterConnection "\\Server01\printer01" WshNetwork.AddWindowsPrinterConnection "\\Server01\printer02" WshNetwork.AddWindowsPrinterConnection "\\Server01\printer03" rem ** Setup default printer ** WshNetwork.SetDefaultPrinter "\\Server01\Printer02" 2
3s-gtech Posted June 28, 2010 Posted June 28, 2010 Same here, our script deletes all printers first, then re-adds them. This ironed out a few quirks. 1
Little-Miss Posted June 28, 2010 Author Posted June 28, 2010 so, if i add... on error resume next Set WshNetwork = CreateObject("WScript.Network") Dim Compname Compname = WSHNetwork.ComputerName Set oPrinters = WshNetwork.EnumPrinterConnections For i = 1 to oPrinters.Count - 1 Step 2 WshNetwork.RemovePrinterConnection oPrinters.Item(i) Next if left(compname,4) = "INFS" then PrinterPath = "\\curricsvr1\JUNIOR-SUITE" PrinterPath2 = "\\curricsvr1\INFANT-SUITE" PrinterPath3 = "\\curricsvr1\FOUNDATION" PrinterPath4 = "\\curricsvr1\INFANT-LIBRARY" PrinterPath5 = "\\curricsvr1\STAFF-ROOM" WshNetwork.AddwindowsPrinterConnection PrinterPath WshNetwork.AddwindowsPrinterConnection PrinterPath2 WshNetwork.AddwindowsPrinterConnection PrinterPath3 WshNetwork.AddwindowsPrinterConnection PrinterPath4 WshNetwork.AddwindowsPrinterConnection PrinterPath5 WshNetwork.SetDefaultPrinter "\\curricsvr1\INFANT-SUITE" end if to my script like this it should work?
DEvans Posted October 1, 2010 Posted October 1, 2010 Downfall of course of removing all printers is that you will lose any local printers you might have installed on local machines as well as delaying your login. If you're running a large network with many networked printers you might find it takes a while to remap them all. In your instance, its probably best to remove that troublesome printer and leave the other printers be. Saves you time and solves the issue. Unless of course you only have like < 8 printers or something, then it shouldn't make too much of a big deal, but watch your local printers. (if any)
wesleyw Posted October 2, 2010 Posted October 2, 2010 I'm not sure but I don't believe that script would delete locally installed printers. Wes
mac_shinobi Posted October 2, 2010 Posted October 2, 2010 I'm not sure but I don't believe that script would delete locally installed printers. Wes Am sure RIC's post is still on edugeek somewhere ref the printer script he did - you could take the bit of coding at the start ref the If statement to check if it is an LPR or USB connection and if so to ignore it otherwise to remove the printer connections as per the chunk of code you added at the start of your snippet and leave the rest of your code as is
chazzy2501 Posted October 4, 2010 Posted October 4, 2010 You could avoid scripting altogether and use client side extensions, if not to map the printers then there is atleast the option to remove all networked printers. Really it's so easy to deploy printers with CSE, as long as it's not on vista.
DEvans Posted October 4, 2010 Posted October 4, 2010 You could take the bit of coding at the start ref the If statement to check if it is an LPR or USB connection and if so to ignore it otherwise to remove the printer connections Or alternatively you could simply perform an IF Statement to see if the printer's name begins with "\\" . Not sure how complex it is to check for USB or LPR, but I introduced a code in my login script to just check the name. Similar to the below. 'Remove all Network printers but not local printers Set Printers = WshNetwork.EnumPrinterConnections If ObjFSO.FileExists(strDirectory & strFile) = false Then For i = 0 to Printers.Count - 1 Step 2 If Left(ucase(Printers.Item(i+1)),2) = "\\" Then WSHNetwork.RemovePrinterConnection Printers.Item(i+1) End IF Next Obviously you would need to change to match your defined objects. Thats what I use anyway. In some cases a login script might not remove local printers, it depends on the script and what commands you have used, I think anyway.
box_l Posted October 6, 2010 Posted October 6, 2010 (edited) this removes printers but leaves ltp and usb ones alone For i = 0 to oPrinters.Count - 1 Step 2 On Error Resume Next if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true else WScript.Echo "No network printers found" end if Next BoX Edited October 6, 2010 by box_l
Earthling Posted October 13, 2010 Posted October 13, 2010 We use rundll32 commands in a login script to delete all installed printers, then to install the printer specific to that room. E.G. rundll32 printui.dll,PrintUIEntry /dn /q /n\\servername\printersharename - deletes a printer rundll32 printui.dll,PrintUIEntry /in /q /n\\servername\printersharename - installs printer Works for us, script runs at log-on, takes about 10 seconds......means a different batch file for every room, but once they're done, they're done. And I don't know about anyone else, but it looks like being a long time before we install or refurbish any new or existing rooms. Or even buy any new printers.
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