meastaugh1 Posted July 15, 2007 Posted July 15, 2007 I see, that sounds alright then. So, the logon script isn't working? Have you tried running it interactively as a logged on student user?
originofsymmetry Posted July 15, 2007 Posted July 15, 2007 What do you mean by that? Me logging in to a client on a machine? If so then I have tried that
meastaugh1 Posted July 15, 2007 Posted July 15, 2007 And no errors, nothing in the event log? How about changing WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1" WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2" to WshNetwork.AddWindowsPrinterConnection "\\testserv\ENGLISH_1" WshNetwork.SetDefaultPrinter "\\testserv\ENGLISH_2"
originofsymmetry Posted July 15, 2007 Posted July 15, 2007 Yay!! I got it working with this: On Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections Dim computerName computerName = LCase(WshNetwork.ComputerName) 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 Select Case (Left(computerName, 5)) Case "eng01" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-2" WshNetwork.SetDefaultPrinter "\\testserv\english-1" Case "eng02" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-2" WshNetwork.SetDefaultPrinter "\\testserv\english-2" Case "mat01" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-2" WshNetwork.SetDefaultPrinter "\\testserv\maths-1" Case "mat02" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-2" WshNetwork.SetDefaultPrinter "\\testserv\maths-2" Case Else ' WScript.Echo "No default printers added" End Select Thnx to everyone who's helped and to Ric_ for writing this script:) Now, to finish off, I'd like to be able to nuke existing connections when a user logs off as opposed to on, so would I use this script as is, or would I need to add anything to it? 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
meastaugh1 Posted July 15, 2007 Posted July 15, 2007 Yeah, you'd need to start the script with: On Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections
mullet_man Posted July 15, 2007 Posted July 15, 2007 This is our printer script One question i am wondering is that if anyone know how to rename the printer when it is added in the script, like you can make a drive mapping and rename the drive mapping to something that kids can understand. Tom Thats what I was hoping could be done as well? Does anyone know how to do this?
TechSupp Posted July 15, 2007 Posted July 15, 2007 As far as I know you can, I've got this running in my script but I have to admit not sure it works 100%. Will have a look in the morning and post it if I have it. Maybe it will help. Just had a look and this is what I have in my script to name the printers. As I said it works for some of the printers but not everyone for some reason. Not too bothered as everyone has not got used to the names that appear and changing them now would only confuse them. '// Map Printers network.AddWindowsPrinterConnection printer1 , "Black and White Printer" network.AddWindowsPrinterConnection printer2 , "Colour Printer" network.AddWindowsPrinterConnection printer3 , "Colour Photocopier"
ZeroHour Posted July 24, 2007 Posted July 24, 2007 I will post my script soon as its years of tweaking and contains code to help log errors and also provide some user feedback as well. Just trying to sanitise it for the real world
mullet_man Posted July 24, 2007 Posted July 24, 2007 Thanks TechSupp I will see if I can get my printers named tomorow!!
mullet_man Posted July 25, 2007 Posted July 25, 2007 As far as I know you can, I've got this running in my script but I have to admit not sure it works 100%. Will have a look in the morning and post it if I have it. Maybe it will help. Just had a look and this is what I have in my script to name the printers. As I said it works for some of the printers but not everyone for some reason. Not too bothered as everyone has not got used to the names that appear and changing them now would only confuse them. '// Map Printers network.AddWindowsPrinterConnection printer1 , "Black and White Printer" network.AddWindowsPrinterConnection printer2 , "Colour Printer" network.AddWindowsPrinterConnection printer3 , "Colour Photocopier" That didn't work :-( Thanks.
ZeroHour Posted July 25, 2007 Posted July 25, 2007 Here is a copy of the script we use here. I use function defined in the top to do the work and we use the built in MS agent to provide feedback to the users. It should be able to figure it all out anyway. The function LogtoEvent is used to log things happening in the script to the event log. It has 3 states although you wont use them all. I have found this to be very useful for diagnosing dodgy printers/drivers that cause the script to fail. Its still not really noob friendly but anyone with a little VBS experience should understand it. Look out for {change} areas in the script also. Good luck printersv2.82.vbs
linkazoid Posted July 27, 2007 Posted July 27, 2007 sorry to dig up a slightly old thread, but i have just managed to get this to work. It wasnt working before because of the LCase, changed this and it work on some rooms but not other becase they are lowercase, is there a way to incorperate both, withotut having to rename the PC's? Cheers Mike
Ric_ Posted July 27, 2007 Author Posted July 27, 2007 @linkazoid: The LCase just changes the name to lowercase so that you can inspect the string without worrying about case - changing to uppercase would have done the same job. Does that make sense?
Ric_ Posted August 3, 2007 Author Posted August 3, 2007 (edited) Since the wiki has moved, some of the extra bits for this script have become lost... if you would like to go to Scripting Printer Addition Based on Location - EduGeek.net Wiki and re-contribute all the different additions it would be great Edited April 6, 2008 by ZeroHour
mac_shinobi Posted August 3, 2007 Posted August 3, 2007 Just a case of using the split function instead using left or right functions makes it easier if there is a common demoninator in the string ie a - symbol to seperate room name from machine number or w/e
FN-GM Posted December 27, 2007 Posted December 27, 2007 Yay!! I got it working with this: On Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections Dim computerName computerName = LCase(WshNetwork.ComputerName) 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 Select Case (Left(computerName, 5)) Case "eng01" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-2" WshNetwork.SetDefaultPrinter "\\testserv\english-1" Case "eng02" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\english-2" WshNetwork.SetDefaultPrinter "\\testserv\english-2" Case "mat01" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-2" WshNetwork.SetDefaultPrinter "\\testserv\maths-1" Case "mat02" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-1" WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-2" WshNetwork.SetDefaultPrinter "\\testserv\maths-2" Case Else ' WScript.Echo "No default printers added" End Select Thnx to everyone who's helped and to Ric_ for writing this script:) Now, to finish off, I'd like to be able to nuke existing connections when a user logs off as opposed to on, so would I use this script as is, or would I need to add anything to it? 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 Hi I have used The script above but it doesn't work, any ideas? This is my script On Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections Dim computerName computerName = LCase(WshNetwork.ComputerName) 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 Select Case (Left(computerName, 5)) Case "HC-IT1-" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2" WshNetwork.SetDefaultPrinter "\\HC-Print\Printer2" ' WScript.Echo "No default printers added" End Select This bit i am lost with this: Select Case (Left(computerName, 5)) Case "HC-IT1-" Is this the computer name? Please help. Z
meastaugh1 Posted December 27, 2007 Posted December 27, 2007 Yes, the first line is selecting the first five characters of the computer name, from the left. (eg if computername is HC-IT1-001, then HC-IT is used). You may want to adjust the 5 to 7 based on the script you provided. If your computer naming scheme follows a similar pattern, then you should be ok.
FN-GM Posted December 27, 2007 Posted December 27, 2007 OK i have altered that but when i run (by double clicking it) the script it does nothing. Any ideas please? Thanks Z
meastaugh1 Posted December 27, 2007 Posted December 27, 2007 In the second line change HC-IT1- to hc-it1- The reason it needs to be lowercase is because line 6 in your script changes the computername variable to lowercase.
FN-GM Posted December 27, 2007 Posted December 27, 2007 Good stuff! What would i do if i need to add another printer in the same room please? Thanks Z
meastaugh1 Posted December 27, 2007 Posted December 27, 2007 So, this is the part of your script that assigns the printers: Select Case (Left(computerName, 7)) Case "hc-it1-" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2" WshNetwork.SetDefaultPrinter "\\HC-Print\Printer2" ' WScript.Echo "No default printers added" End Select Lines 3 and 4 seem to be duplicated. You can just change the UNC of the printer share on line 4. Then duplicate and modify the UNC as necessary for additional printers. For example, the following would assign printer1 and printer2 (default) on computer names beginning with hc-it1-. Printer3 (default) and printer4 will be assigned to computer names beginning with hc-it2-: Select Case (Left(computerName, 7)) Case "hc-it1-" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer1" WshNetwork.SetDefaultPrinter "\\HC-Print\Printer2" Case "hc-it2-" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer3" WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer4" WshNetwork.SetDefaultPrinter "\\HC-Print\Printer3" Case Else ' WScript.Echo "No default printers added" End Select
FN-GM Posted December 27, 2007 Posted December 27, 2007 Thanks, will fully test when we get back. Thanks Z
FN-GM Posted December 27, 2007 Posted December 27, 2007 Sorry to double post, but just in case meastaugh1 already read my last post, so i didn't edit. Anyway can this be added to a start-up script, I ask this because I want to introduce this on certain computers only for now. I only want it to work on one ICT room not all the computers in the school. If not how do I adapt it so it will work with a start-up script please? Thanks Z
meastaugh1 Posted December 27, 2007 Posted December 27, 2007 Hmm, network printer mappings are per-user connections. To deploy to a testbed of computers, I suggest you stick it in a GPO in loopback merge mode and deploy it as a login script. Having said that, you can add a network printer mapping on a computer for all users. I'm sure you'd only need to run it once on each computer, and wouldn't need to be run as a startup script. http://maisonbisson.com/blog/post/11106
FN-GM Posted December 27, 2007 Posted December 27, 2007 Ok I will try loopback when I get back So if i add the following to a .bat script and set it as a start-up script it should work? rundll32 printui.dll,PrintUIEntry /ga /n\\printers\%printername% Thank you for all your help Z
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