|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GPO logon script
I would like to have a GPO logon script to map printers based on the
classroom where the computer is located. I have students that move from room to room and would like to map the printer for the room that they are in. I was thinking of using an .ini file to get the printer to use based on the room the computer is in. I have a number of rooms and thought this would be the easiest way. If I use an .ini file, where would I have to place the .ini file so that it would be accessable for the user log on? Any other suggestions on how I might handle this type of printer mapping? Any suggestions or help would be appreciated. Thanks Art wrote:
Show quote >I would like to have a GPO logon script to map printers based on the I place my computer objects in groups and the logon script maps the printer > classroom where the computer is located. I have students that move from > room > to room and would like to map the printer for the room that they are in. > I > was thinking of using an .ini file to get the printer to use based on the > room the computer is in. I have a number of rooms and thought this would > be > the easiest way. > If I use an .ini file, where would I have to place the .ini file so that > it > would be accessable for the user log on? > Any other suggestions on how I might handle this type of printer mapping? > Any suggestions or help would be appreciated. > Thanks according to computer group membership. This assumes they are desktop computers that don't move. In a VBScript logon script (if all clients have Windows 2000 or above): ================= Set objNetwork = CreateObject("Wscript.Network") ' Retrieve computer Distinguished Names. Set objSysInfo = CreateObject("ADSystemInfo") strComputerDN = objSysInfo.computerName ' Bind to the computer object. Set objComputer = GetObject("LDAP://" & strComputerDN) ' Bind to group. Set objGroup = GetObject("LDAP://cn=Room104,ou=Students,dc=MyDomain,dc=com") ' Check for group membership. If (objGroup.IsMember(objComputer.AdsPath) = True) Then objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser2" objNetwork.SetDefaultPrinter "\\PrintServer\HPLaser2" End If ================ If you have lots of rooms, this would involve lots of groups and lots of membership checks. An alternative is to enumerate the groups the computer object is a member of. Perhaps: =============== Set objNetwork = CreateObject("Wscript.Network") ' Retrieve computer Distinguished Names. Set objSysInfo = CreateObject("ADSystemInfo") strComputerDN = objSysInfo.computerName ' Bind to the computer object. Set objComputer = GetObject("LDAP://" & strComputerDN) ' Enumerate groups computer is a member of. For Each objGroup In objComputer.Groups ' Retrieve NT name of group. Make lower case. strGroupName = LCase(objGroup.sAMAccountName) Select Case strGroupName Case "Room104" objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser2" objNetwork.SetDefaultPrinter \\PrintServer\HPLaser2 Exit For Case "Room105" objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser3" objNetwork.SetDefaultPrinter "\\PrintServer\HPLaser3" Exit For End Select Next ============= I don't know of a good way to read an ini file, but the FileSystemObject can read any text file. This option would be a bit more work, requiring setup on each computer. The most obvious place to save the file is on the local computer, perhaps in the root of the c: drive. Otherwise, you would have to setup a file for each computer in a shared location, with the file maybe named after the computer. If you go this route, I would suggest a one line text file with the unc path to the printer. Then a VBScript program can read the file with code similar to: =================== Const ForReading = 1 ' Specify location of local text file with printer. strFile = "c:\printer.txt" ' Open the file for read access. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, ForReading) ' Read the first line of the file. strPrinter = Trim(objFile.ReadLine) ' Close the file. objFile.Close ' Map printer specified. If (strPrinter <> "") Then objNetwork.AddWindowsPrinterConnection strPrinter objNetwork.SetDefaultPrinter strPrinter End If ============= You might need to add some validation, such as checking if the file exists before attempting to open it. If you place files for each computer in a shared location, name the file after the NT name (NetBIOS name) of the computer, then retrieve the name from the wshNetwork object. Set objNetwork = CreateObject("Wscript.Network") strComputer = objNetwork.ComputerName strFile = "\\MyServer\MyShare\" & strComputer & ".txt" Thanks Richard,
I really appreciate the quick response. I think I will go for your suggestion and place the computers in groups and then enumerate the groups the computer belongs to. Sounds like that would be the best for on going maintenance, etc. Thanks again Show quote "Richard Mueller [MVP]" wrote: > Art wrote: > > >I would like to have a GPO logon script to map printers based on the > > classroom where the computer is located. I have students that move from > > room > > to room and would like to map the printer for the room that they are in. > > I > > was thinking of using an .ini file to get the printer to use based on the > > room the computer is in. I have a number of rooms and thought this would > > be > > the easiest way. > > If I use an .ini file, where would I have to place the .ini file so that > > it > > would be accessable for the user log on? > > Any other suggestions on how I might handle this type of printer mapping? > > Any suggestions or help would be appreciated. > > Thanks > > I place my computer objects in groups and the logon script maps the printer > according to computer group membership. This assumes they are desktop > computers that don't move. In a VBScript logon script (if all clients have > Windows 2000 or above): > ================= > Set objNetwork = CreateObject("Wscript.Network") > > > ' Retrieve computer Distinguished Names. > Set objSysInfo = CreateObject("ADSystemInfo") > strComputerDN = objSysInfo.computerName > > ' Bind to the computer object. > Set objComputer = GetObject("LDAP://" & strComputerDN) > > > ' Bind to group. > Set objGroup = GetObject("LDAP://cn=Room104,ou=Students,dc=MyDomain,dc=com") > > ' Check for group membership. > If (objGroup.IsMember(objComputer.AdsPath) = True) Then > objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser2" > objNetwork.SetDefaultPrinter "\\PrintServer\HPLaser2" > End If > ================ > If you have lots of rooms, this would involve lots of groups and lots of > membership checks. An alternative is to enumerate the groups the computer > object is a member of. Perhaps: > =============== > Set objNetwork = CreateObject("Wscript.Network") > > > ' Retrieve computer Distinguished Names. > Set objSysInfo = CreateObject("ADSystemInfo") > strComputerDN = objSysInfo.computerName > > ' Bind to the computer object. > Set objComputer = GetObject("LDAP://" & strComputerDN) > > ' Enumerate groups computer is a member of. > For Each objGroup In objComputer.Groups > ' Retrieve NT name of group. Make lower case. > strGroupName = LCase(objGroup.sAMAccountName) > Select Case strGroupName > Case "Room104" > objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser2" > objNetwork.SetDefaultPrinter \\PrintServer\HPLaser2 > Exit For > Case "Room105" > objNetwork.AddWindowsPrinterConnection "\\PrintServer\HPLaser3" > objNetwork.SetDefaultPrinter "\\PrintServer\HPLaser3" > Exit For > End Select > Next > ============= > I don't know of a good way to read an ini file, but the FileSystemObject can > read any text file. This option would be a bit more work, requiring setup on > each computer. The most obvious place to save the file is on the local > computer, perhaps in the root of the c: drive. Otherwise, you would have to > setup a file for each computer in a shared location, with the file maybe > named after the computer. > > If you go this route, I would suggest a one line text file with the unc path > to the printer. Then a VBScript program can read the file with code similar > to: > =================== > Const ForReading = 1 > > ' Specify location of local text file with printer. > strFile = "c:\printer.txt" > > ' Open the file for read access. > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objFile = objFSO.OpenTextFile(strFile, ForReading) > > ' Read the first line of the file. > strPrinter = Trim(objFile.ReadLine) > > ' Close the file. > objFile.Close > > ' Map printer specified. > If (strPrinter <> "") Then > objNetwork.AddWindowsPrinterConnection strPrinter > objNetwork.SetDefaultPrinter strPrinter > End If > ============= > You might need to add some validation, such as checking if the file exists > before attempting to open it. If you place files for each computer in a > shared location, name the file after the NT name (NetBIOS name) of the > computer, then retrieve the name from the wshNetwork object. > > Set objNetwork = CreateObject("Wscript.Network") > strComputer = objNetwork.ComputerName > strFile = "\\MyServer\MyShare\" & strComputer & ".txt" > > -- > Richard Mueller > Microsoft MVP Scripting and ADSI > Hilltop Lab - http://www.rlmueller.net > -- > > > |
|||||||||||||||||||||||