Andi Posted April 24, 2007 Posted April 24, 2007 I see, thanks Ric and Geoff for your help so far. So if the users run the logon script no matter where they logon it will only map the printer if they are on a terminal station of course. (We have both thin and thick clients here). I'll add my location now.
Ric_ Posted April 24, 2007 Author Posted April 24, 2007 How good am I? Wikified all this at http://www.russdev.com/edugeek/doku.php?id=printer_assignment
Andi Posted April 24, 2007 Posted April 24, 2007 Ric's script seems to be working a treat for my thin clients. Thanks for all your help.
Ric_ Posted April 24, 2007 Author Posted April 24, 2007 @Andi: As mentioned in the Wiki, this script will work on both fat and thin clients without modification.... that's how I use it
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 Just a note on the split, you can also use it to look at the characters after the hyphen ( which is the split character we are using because it is the common denomenator ) Which you do by altering the index value of x from x(0) to x(1). Basically the split goes through the whole string and trys to find any of the characters that we told it to find, in this case the hyphen and it will store any values in between or after the hyphen into an array. So if the string we were splitting was RM-01-Computer then x(0) would be the first array which would contain RM x(1) would be 01 x(2) would be Computer So if I wanted to see what was in the middle of computer and RM then I would just use x(1) as that will always retrieve the middle value assuming that there will be 2 hyphens aka 3 values to retrieve. If it was just the case that it will be RM-01 and you wanted what was after RM- then you would use x(1). Basically using the arrays index Just thought I would mention that because the wiki says if you have a hyphen in your computer name and your want to look at the characters before that you could use..... which wasn't true
Ric_ Posted April 24, 2007 Author Posted April 24, 2007 @gecko: It is true because it says "a hyphen" - it would only be incorrect if it said "two hyphens" I only stuck it in as an example anyway... you can always edit the wiki and add additional bits that you feel would be useful to others (hint hint)
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 fair enough , better find a decent example of the split and post the URL etc lol @ hint hint
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 Any chance you can put a link on that wiki to create a new page so that I can do something similiar to this page : http://www.devguru.com/technologies/vbscript/QuickRef/split.html But on the coded examples I want to take out all the % symbols and such
Ric_ Posted April 24, 2007 Author Posted April 24, 2007 @gecko: Scroll to the bottom of the page and hit the 'Edit this page' button. I have added a subheading all about split() just for you Just write something like 'Added by...' in italics so we know who to blame
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 @gecko: Scroll to the bottom of the page and hit the 'Edit this page' button. I have added a subheading all about split() just for you Just write something like 'Added by...' in italics so we know who to blame by who to blame..... you mean who to give credit to LOL I just wanted to make sure that people knew that it could be used for both the before the common character ( such as the hyphen ) as well as being used after the common character aka the hyphen ( again ). So it is useful in both senses without having to use left or right of the computer or client name by so many characters ( because you dont know how many characters different people use ) where as the split just splits regardless of how many characters which saves the hassle of counting by x amount of characters which I thought would save a bit of hassle Just one persons opinion and or $0.02 cents take it or leave it as they say
Ric_ Posted April 24, 2007 Author Posted April 24, 2007 @gecko: Only winding you up! Seriously though... thanks for your input to the wiki. One day we will truly have a great resource
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 maybe being a bit thick here but at the end you show them how to assign the script via startup and logon scripts, but can't you assign it via one or the other and not both and which one would be better to assign it as or does that depend on if they are assigning it via computer objects or user objects ( ie if you assign the script as logon then its to user objects and if its startup then its to computer objects on an OU that contains computer objects ) If that makes sense ? Yeah I gathered you were winding me up lol, I was doing the same, the whole give and take thing Could do with a wiki index so that the important things that get wikied can be found quickly as it builds up in a html format so that the index are links that can be clicked on to take people to the relevant sections
Ric_ Posted April 24, 2007 Author Posted April 24, 2007 You need the startup section for the first section (maybe I should have explained this better - I will revise it when someone unlocks the page for editting ) The wiki will (hopefully) soon be swallowed by EduGeek 2.0 where everything will be easy to access in a timely fasion
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 I'm done on that page and have been for about 4 mins I just wanted to make sure that the 2 code snippers for the split function were showing up as they were meant to and I figured out that I was putting and not when I should of been putting obviously
mac_shinobi Posted April 24, 2007 Posted April 24, 2007 Im curious, with regards to the permissions thing on the first one, most likely a blonde moment here but you say it fails on the installing of printer drivers, but considering that the printer is actually installed on the server ( print server or whatever you want to call it ). and when you script it it is making a connection to the server ( which has the drivers installed already on it ) to the shared printer to be used by multiple users, why would it need the driver on the client machine if its just connecting to the server to tell the printer on the server how to print the document.. I swear I must be missing something here and Im guessing I will find out soon enough.... Just with the vbscript coding the commands are AddWindowsPrinterConnection RemovePrinterConnection Etc which makes me think its just a connection and ( Am most likely wrong here otherwise you wouldn't make the script a startup one ) But if its just a connection why would the client systems need the driver to print to a shared printer ? I know that the client systems do need the driver for the relevant printer in question but I just dont understand why if your centralising the printer with the installed driver on that centralised system as to why you would have the need to repeatdly install the driver on all the other systems ?
Geoff Posted April 24, 2007 Posted April 24, 2007 No, Windows clients needs the drivers because the job processing is done on the client rather than the server. Stupid, I know.
mac_shinobi Posted April 25, 2007 Posted April 25, 2007 Is that the same on other O/S's with regards to processing it on the client before its sent to a shared printer or is this a microsoft thing or what ?
Ric_ Posted April 25, 2007 Author Posted April 25, 2007 @gecko: The reason that a AddWindowsPrinterConnection installs the drivers is because Windows tried to copy the drivers from the server if they are available. As the script runs with SYSTEM-level permissions in a startup script, this is successful where it would not be with user-level permissions. Not all OSs process the print job themselves. For instance, anything that uses CUPS (e.g. Linux, OS X, Unix, BSD) will do it 'properly'.
Andi Posted April 25, 2007 Posted April 25, 2007 We already have a working setup using con2prt to allocate printers to our fat clients depending on their OU. I was just looking for a solution for my thin clients and this is great, thanks again.
tomscaper Posted June 14, 2007 Posted June 14, 2007 This is our printer script 'Printer Script 'This script checks the Computer Group Membership 'and installs depending on the group. Option explicit dim objNetwork, objComputer, ObjPrinter dim strDomain, strComputerName Set objNetwork = WScript.CreateObject("Wscript.Network") strDomain = objNetwork.UserDomain strComputerName = objNetwork.ComputerName Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputerName & ",computer") Set objPrinter = CreateObject("WScript.Network") If isComputerMember("LRC") Then objPrinter.AddWindowsPrinterConnection "\\prnt_svr\printer1" objPrinter.SetDefaultPrinter "\\prnt_svr\printer1" End If Function IsComputerMember(sGroup) Dim oGroup on error resume next Set oGroup = GetObject("WinNT://" & strDomain & "/" & sGroup & ",group") IsComputerMember = CBool(oGroup.IsMember(objComputer.ADsPath & "$")) Set oGroup = Nothing If not Err.Number = 0 Then 'isComputerMember could not locate group end if on error goto 0 End Function We created groups in the active directory, and added the computers to those groups, this was a much easier way as you can set up the printer scripts and add computers as you get them to the different groups. 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
originofsymmetry Posted July 15, 2007 Posted July 15, 2007 Right I have tried Rics scripts but am not getting any success, heres the score: Servername=testserv Printers=ENGLISH_1. ENGLISH_2, MATHS_1, MATHS_2 * They are attached to the server, not directly to the clients, they are shared. The clients are organised in OU's - english and maths, with the following names: eng01, eng02, mat01, mat02 My problem seems to arise with the first script, installing printer drivers: On Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections 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 Dim printServer printServer = "testserv" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_2" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_2" oPrinters = WshNetwork.EnumPrinterConnections 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 This script used to run just after the user typed there name and Applyng Computer Configuration and Running Logon Scripts would show, but for some reason, this has stopped happening - the script is located in GMPC and is appleid to eng01, eng02..... The second os the user logon script which is run for all users using a STUDENT group I created and assigined eveyone to 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) Dim printServer printServer = "testserv" Select Case (Left(computerName, 5)) Case "eng01" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1" WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2" objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1" Case "eng02" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1" WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2" objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1" Case "mat01" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1" WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2" objNetwork.SetDefaultPrinter "\\testserv\MATHS_1" Case "mat02" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1" WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2" objNetwork.SetDefaultPrinter "\\testserv\MATHS_1" Case Else ' WScript.Echo "No default printers added" End Select When using this script on its own I receive no errors from Windows so I assume there are no errors with, it, just the driver install one, and how can I get it to apply again, it just stopped seemingly for no reason. Sorry for the big post but wanted to give as much info as possible thnx
meastaugh1 Posted July 15, 2007 Posted July 15, 2007 I assume you are just assigning printers to XP clients, and not thin clients? If so, then I'm sure you just need the one logon script: 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.SetDefaultPrinter "\\"testserv"\ENGLISH_2" objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1" Case "eng02" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1" WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2" objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1" Case "mat01" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1" WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2" objNetwork.SetDefaultPrinter "\\testserv\MATHS_1" Case "mat02" WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1" WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2" objNetwork.SetDefaultPrinter "\\testserv\MATHS_1" Case Else ' WScript.Echo "No default printers added" End Select What's the naming convention of your workstations? You are aware that printers are being assigned according to first five characters of the computer name, and not the first five characters of the OU in which they reside?
originofsymmetry Posted July 15, 2007 Posted July 15, 2007 the naming convention for the computers is the first three letters from the department then the computer number, I dont have it all split for room number, the number (01)etc. just goes on for a department in whole, may it be the cause? And yes, its just to a bunch of XP clients, thanks for clearing that bit up
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