meastaugh1 Posted December 27, 2007 Posted December 27, 2007 I wouldn't have thought you'd even need the bat. You can probably just add the command straight into the policy: Script name: c:\windows\system32\rundll32.exe Script parameters: c:\windows\system32\printui.dll,PrintUIEntry /ga /n\\printers\%printername% Haven't tested it, but you can give it a go when you get back.
meastaugh1 Posted December 27, 2007 Posted December 27, 2007 If you're running a startup script, presumably you'd be executing it through GPO. In that case, where you'd specify the .bat file in the startup script section of the GPO, you can just specify the above instead, thereby negating the need for a batch file. Not particularly significant either way though.
maniac Posted December 27, 2007 Posted December 27, 2007 Word of caution on adding printers with printUI; I've got into very messy situations using the printUI method of adding printers. Mainly because they can only be removed using the same command, so if you move machines to different areas of the school or rename your printers, you need to write a remove command for them first, then re-run the add command. Also I seem to recall running it more than once will result in the same printer being added multiple times, so be very careful if you set it as a startup script that it only gets run once! Is there any particular reason they can't be added via a logon script, as this is mine and most others prefered method? Mike.
FN-GM Posted December 28, 2007 Posted December 28, 2007 s there any particular reason they can't be added via a logon script, as this is mine and most others prefered method? Because it will be only used on some machines not all, if it is added to a logon script for all users if they log onto a computer without the printers on that machine having them in the script it will delete all the printers but not put any new ones on. Does that make sense? Z
maniac Posted December 28, 2007 Posted December 28, 2007 If you make the delete printer connections line only run for the necessary machines like the add lines do, then all machines will run the script but machines that do meet the criteria will do nothing therefore leaving any existing printer connections intact. I'm just sure you will run into problems adding printers with the printUI command, and it can be a PITA to sort out if you do (trust me, I've been there!) If you do go down the route of using it, try it out throughly on one machine first before you unlesh it on your network. Mike.
FN-GM Posted December 28, 2007 Posted December 28, 2007 I will be using the VBS script i think. How do i get it to work on certain machines?
maniac Posted December 28, 2007 Posted December 28, 2007 Looking at the script you're using on the previous page, it would make it a bit messy, owing to the loop technique used to remove all the network printers (I think there is a slightly shorter method of doing this, but it escapes me at the moment) All you need to do it remove the single instance of the 'remove printer connections' loop at the beginning of the script, and place a copy of it under each 'case' statement. this would ensure it only removes printer connections on machines where it's going to add them again. It will make the script a bit longer, but it will work just fine. Mike.
FN-GM Posted December 28, 2007 Posted December 28, 2007 well i will look into that if the loopback doesn't work. I say that because the script works fine now and i can understand it just going to test it with loopback. I will let you know... Z
mac_shinobi Posted February 20, 2009 Posted February 20, 2009 Found it and here it is : Dim SleepTime 'upper school printers Dim IT1 Dim IT2 Dim IT3 Dim IT4 Dim IT6 Dim TechU Dim LibrarySixth 'lower school printers Dim ICT5 Dim ICT6 Dim ICT8 Dim TechL Dim EdSupport Dim AName IT1 = "kyoceraM" IT2="kyit2" IT3="kyit3" IT4="kyit4" IT6="IT6Las" TechU="kdt" LibrarySixth="kyoceraL" ICT5="HPLaserJ" ICT6="HP-ICT6" ICT8="HP-ICT8" TechL="KyoceraF" EdSupport="BrotherEd" SleepTime=15 Set WSHNetwork = CreateObject("WScript.Network") strComputer = WSHNetwork.ComputerName AName = Left(strComputer,Len(strComputer)-4) Select Case AName Case "IT1" call AddPrinter("\\cse2k01\",IT1) MsgBox "Added Printer : " & IT1 Case "IT2" call AddPrinter("\\cse2k01\",IT2) MsgBox "Added Printer : " & IT2 Case "IT3" call AddPrinter("\\cse2k01\",IT3) MsgBox "Added Printer : " & IT3 Case "IT4" call AddPrinter("\\cse2k01\",IT4) MsgBox "Added Printer : " & IT4 Case "DT" call AddPrinter("\\cse2k01\",TechU) MsgBox "Added Printer : " & TechU Case "IT6" call AddPrinter("\\cse2k01\",IT6) MsgBox "Added Printer : " & IT6 Case "LibrarySixth" call AddPrinter("\\cse2k01\",LibrarySixth) MsgBox "Added Printer : " & LibrarySixth Case "ICT5" call AddPrinter("\\cse2k01\",ICT5) MsgBox "Added Printer : " & ICT5 Case "ICT6" call AddPrinter("\\cse2k01\",ICT6) MsgBox "Added Printer : " & ICT6 Case "ICT8" call AddPrinter("\\cse2k01\",ICT8) MsgBox "Added Printer : " & ICT8 Case "DTLS" call AddPrinter("\\cse2k01\",TechL) MsgBox "Added Printer : " & TechL Case "ES" call AddPrinter("\\cse2k01\",EdSupport) MsgBox "Added Printer : " & EdSupport End Select Public Function AddPrinter(ByRef Server,ByRef strPrinter) Set WshNetwork = CreateObject("WScript.Network") rem ** This will delete existing printers ** On Error Resume Next Set oPrinters = WshNetwork.EnumPrinterConnections For i = 1 to oPrinters.Count - 1 Step 2 WshNetwork.RemovePrinterConnection oPrinters.Item(i) Next rem ** Setup new printer connection ** WshNetwork.AddWindowsPrinterConnection Server & strPrinter rem ** Pause Script ** WScript.Sleep SleepTime*1000 rem ** Setup default printer ** WshNetwork.SetDefaultPrinter Server & strPrinter End Function printvbs.vbs
linkazoid Posted August 27, 2009 Posted August 27, 2009 All you need to do it remove the single instance of the 'remove printer connections' loop at the beginning of the script, and place a copy of it under each 'case' statement. this would ensure it only removes printer connections on machines where it's going to add them again. It will make the script a bit longer, but it will work just fine. Mike. Can someone help me with this, we've been using this script for a while, but have now changed our GPOs and AD structure... How can I edit the original script not to delete printers from computers named ADMIN- or LAPTOP- ? Cheers, Michael
linkazoid Posted February 17, 2010 Posted February 17, 2010 I'm still having problems with the script. We would like this script to run as it should i.e delete printers then map according to the script below but we would like any computers named ADMIN-**** & LAPTOP-**** to be exempt and leave any printer mapped. If someone can shed some light and show me where i need to make changes that would be great. I have had to edit the script below due to it's vast character length, but attached script is full. Thanks Michael ' Script to add network printers to workstations and thin clients ' ' Author: Ric Charlton, 07/07/04, edited by Michael 24/12/09 - Added New Section to bottom ' Declare variables and enumerate existing printer connections Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections Dim computerName computerName = LCase(WshNetwork.ComputerName) if (computerName = "svrts1") then _ computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%")) ' Degugging line> WScript.Echo "ComputerName variable: " & computerName ' Delete existing connections to network printers 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 ' Add printer connections dependant upon location Select Case (Left(computerName, 3)) Case "lrc" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\lrc" WshNetwork.SetDefaultPrinter "\\sharepoint\lrc" Case "saw" WshNetwork.AddWindowsPrinterConnection "\\saw\saw" WshNetwork.SetDefaultPrinter "\\saw\saw" End Select Select Case (Left(computerName, 4)) Case "art1" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\ArtColourA3_PS" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\art" WshNetwork.SetDefaultPrinter "\\sharepoint\art" Case "rm30" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room305" WshNetwork.SetDefaultPrinter "\\sharepoint\Room305" Case "art2" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\ArtColourA3_PS" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\art" WshNetwork.SetDefaultPrinter "\\sharepoint\art" Case "rm30" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\mathstemp" WshNetwork.SetDefaultPrinter "\\sharepoint\mathstemp" Case "rm31" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\room305" WshNetwork.SetDefaultPrinter "\\sharepoint\305" Case "rm71" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Humanities" WshNetwork.SetDefaultPrinter "\\sharepoint\Humanities" Case "rm72" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Humanities" WshNetwork.SetDefaultPrinter "\\sharepoint\Humanities" Case "rm73" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Humanities" WshNetwork.SetDefaultPrinter "\\sharepoint\Humanities" Case "rm66" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room666" WshNetwork.SetDefaultPrinter "\\sharepoint\Room666" Case "mro-" WshNetwork.AddWindowsPrinterConnection "\\print\sharpphotocopier" WshNetwork.SetDefaultPrinter "\\print\sharpphotocopier" End Select Case "lrc" Select Case (Left(computerName, 4)) Case "lrc-" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\lrc" WshNetwork.SetDefaultPrinter "\\sharepoint\lrc" Case "lrcl" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\lrc" WshNetwork.SetDefaultPrinter "\\sharepoint\lrc" End Select Case "rm14" Select Case (Left(computerName, 5)) Case "rm142" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\l2l8" WshNetwork.SetDefaultPrinter "\\sharepoint\l2l8" Case "rm144" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\l2l9" WshNetwork.SetDefaultPrinter "\\sharepoint\l2l9" End Select Case "rm41" Select Case (Left(computerName, 5)) Case "rm412" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room412" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room412Colour" WshNetwork.SetDefaultPrinter "\\sharepoint\Room412" Case "rm411" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\room411" WshNetwork.SetDefaultPrinter "\\sharepoint\room411" End Select Case "rm33" Select Case (Left(computerName, 5)) Case "rm334" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\englishoffice" WshNetwork.SetDefaultPrinter "\\sharepoint\englishoffice" End Select Case "rm61" Select Case (Left(computerName, 5)) Case "rm611" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room611" WshNetwork.SetDefaultPrinter "\\sharepoint\Room611" Case "rm612" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room612Color" WshNetwork.SetDefaultPrinter "\\sharepoint\Room612Color" End Select Case "rm63" Select Case (Left(computerName, 5)) Case "rm632" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\l2l7" WshNetwork.SetDefaultPrinter "\\sharepoint\l2l7" End Select Case "rm51" Select Case (Left(computerName, 5)) Case "rm513" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room513" WshNetwork.SetDefaultPrinter "\\sharepoint\Room513" Case "rm511" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\englishOffice" WshNetwork.SetDefaultPrinter "\\sharepoint\englishOffice" Case "rm512" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\englishOffice" WshNetwork.SetDefaultPrinter "\\sharepoint\englishOffice" End Select Case Else ' WScript.Echo "No default printers added" End Select Select Case (computerName) Case "admin-2454" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\timeout" WshNetwork.SetDefaultPrinter "\\sharepoint\timeout" End Select printer.vbs
linkazoid Posted October 1, 2010 Posted October 1, 2010 It appears that we have another problem at the mo. It seems that if the printer is not on, for example if Room412 is not on the Room412 Colour does not get mapped either. Case "rm412" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room412" WshNetwork.AddWindowsPrinterConnection "\\sharepoint\Room412Colour" WshNetwork.SetDefaultPrinter "\\sharepoint\Room412" Is there any was I can force it to carry on if a printer is swithed off? This did not seem to be a problem until recently Thanks Michael
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