FN-GM Posted October 5, 2010 Posted October 5, 2010 Hi, Is is possible for a logon script to run based on the group a compter is in? Basically i want to create a script that will see if the computer is in the group "V213Mono" and if so run this command: rundll32 printui.dll,PrintUIEntry /y /n "\\KP-Print\V213Mono" Thanks
siuko Posted October 5, 2010 Posted October 5, 2010 If you use kix scripts to do your logon scripts then there is a way to do it using certain kixscript udf scripts. I dont know if you can do it with any other type of logon script - let me know if you need the kixscript info
6Foot2 Posted October 5, 2010 Posted October 5, 2010 We use Kix Scripts. Stage one: We have a batch file: Staff Printers.BAT: [staff Printers.Bat is a logon script set in Active Directory] echo off \\DomainController.ChildDomain.ParentDomain.local\netlogon\wkix32.exe /b \\DomainController.ChildDomain.ParentDomain.local\netlogon\StaffPrinters.kix Staff Printers.KIX looks like this: ;Classroom and administration workstations SELECT ;Rooms 1 to 5 CASE LEFT(@WKSTA, 5) = "Room1" AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Administration Office Kyocera") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\English Office") SetDefaultPrinter ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") CASE LEFT(@WKSTA, 5) = "Room2" AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Administration Office Kyocera") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\English Office") SetDefaultPrinter ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") ... ... CASE LEFT(@WKSTA, 13) = "AdminOffice01" AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Administration Office Kyocera") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\English Office") SetDefaultPrinter ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") ENDSELECT So for a station called AdminOffice01 a user would get Staff Room, Admin Office Kyocera, English Office printers and the Staff Room Printer would be selected as the default for the user logging onto that station. For students we do something similar except that the logon script is attached to the station OU and that script only runs for students. HTH.
FN-GM Posted October 5, 2010 Author Posted October 5, 2010 New GPO and use the security filtering Would that work as the group is a computer group and the script is a user script. I dont want to use loopback either If you use kix scripts to do your logon scripts then there is a way to do it using certain kixscript udf scripts. I dont know if you can do it with any other type of logon script - let me know if you need the kixscript info We use Kix Scripts. Stage one: We have a batch file: Staff Printers.BAT: [staff Printers.Bat is a logon script set in Active Directory] echo off \\DomainController.ChildDomain.ParentDomain.local\netlogon\wkix32.exe /b \\DomainController.ChildDomain.ParentDomain.local\netlogon\StaffPrinters.kix Staff Printers.KIX looks like this: ;Classroom and administration workstations SELECT ;Rooms 1 to 5 CASE LEFT(@WKSTA, 5) = "Room1" AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Administration Office Kyocera") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\English Office") SetDefaultPrinter ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") CASE LEFT(@WKSTA, 5) = "Room2" AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Administration Office Kyocera") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\English Office") SetDefaultPrinter ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") ... ... CASE LEFT(@WKSTA, 13) = "AdminOffice01" AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\Administration Office Kyocera") AddPrinterConnection ("\\PrintServer.ChildDomain.ParentDomain.Local\English Office") SetDefaultPrinter ("\\PrintServer.ChildDomain.ParentDomain.Local\Staff Room") ENDSELECT So for a station called AdminOffice01 a user would get Staff Room, Admin Office Kyocera, English Office printers and the Staff Room Printer would be selected as the default for the user logging onto that station. For students we do something similar except that the logon script is attached to the station OU and that script only runs for students. HTH. Thansk but i dont need to deploy printers. I do this already by AD. Thanks
sted Posted October 5, 2010 Posted October 5, 2010 i know this sounds a long way round but should work could you create a policy that was filtered by group that copied a shortcut to the scipt to the all user startup folder on the pc. I THINK and this is the bit i havnt tried that if you then set sat the permissions on the script to say pupils deny it should only run when staff(or admins) run and only on hte machines its needed on
FN-GM Posted October 5, 2010 Author Posted October 5, 2010 i know this sounds a long way round but should work could you create a policy that was filtered by group that copied a shortcut to the scipt to the all user startup folder on the pc. I THINK and this is the bit i havnt tried that if you then set sat the permissions on the script to say pupils deny it should only run when staff(or admins) run and only on hte machines its needed on Good idea. I will probably do that. But it would be nice if i could have a more tidy way if possible
bladedanny Posted October 5, 2010 Posted October 5, 2010 I dont want to use loopback either This is the way I do it. add to new or existing GPO put bat file in user logon script and enable user group loopback processing mode. Works and I think its quite a tidy way of doing it.
box_l Posted October 6, 2010 Posted October 6, 2010 (edited) Here is a script i use ' ************************************************************ ' *** Setup Network Printers based on Group Membership *** ' ************************************************************ on error resume next Set oP=objNetwork.EnumPrinterConnections lgCnt=oP.Count Do While lgCnt>0 objNetwork.RemovePrinterConnection oP.Item(lgCnt-1),True,True lgCnt=lgCnt-2 Loop If IsComputerMember("green_area") or (left(strComputerName, 10))="2063-GREEN" Then WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\GREEN4650DN" WshNetwork.SetDefaultPrinter "\\2063-fs02\GREEN4650DN" End If If IsComputerMember("blue_area") or (left(strComputerName, 9))="2063-BLUE" Then WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\BLUE4650DN" WshNetwork.SetDefaultPrinter "\\2063-fs02\BLUE4650DN" End If If IsComputerMember("red_area") or (left(strComputerName, 8))="2063-RED" Then WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\RED4650DN" WshNetwork.SetDefaultPrinter "\\2063-fs02\RED4650DN" End If If IsComputerMember("Staff") or (left(strComputerName, 9))="2063-TLAP" Then WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\RED4650DN" WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\BLUE4650DN" WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\lib3600n" WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\6F2600n" WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\6M2600n" WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\REC3600n" WshNetwork.AddWindowsPrinterConnection "\\2063-fs02\GREEN4650DN" End If End If ' ********************************* ' *** End Printer Mappings *** ' ********************************* Function IsMember(strGroup) ' Function to test for group membership, ' returns True If the user or computer is a member of the group. If IsEmpty(objGroupList) Then Call LoadGroups End If IsMember = objGroupList.Exists(strGroup) End Function Function IsComputerMember(sGroup) Dim oGroup on error resume next Set oGroup = GetObject("WinNT://" & strDomain & "/" & sGroup & ",group") IsComputerMember = CBool(oGroup.IsMember(objComputer2.ADsPath & "$")) Set oGroup = Nothing If not Err.Number = 0 Then 'isComputerMember could not locate group end if on error goto 0 End Function Sub LoadGroups() '------------------------------------------------ ' Subroutine to populate dictionary object with group memberships. ' objUser is the user or computer object, with global scope. ' objGroupList is a dictionary object, with global scope. Dim arrbytGroups, j, arrstrGroupSids(), objGroup Set objGroupList = CreateObject("Scripting.Dictionary") objGroupList.CompareMode = vbTextCompare objUser.GetInfoEx Array("tokenGroups"), 0 arrbytGroups = objUser.Get("tokenGroups") If TypeName(arrbytGroups) = "Byte()" Then ReDim arrstrGroupSids(0) arrstrGroupSids(0) = OctetToHexStr(arrbytGroups) Set objGroup = GetObject("LDAP:// & ">") objGroupList(objGroup.sAMAccountName) = True Set objGroup = Nothing Exit Sub End If If UBound(arrbytGroups) = -1 Then Exit Sub End If ReDim arrstrGroupSids(UBound(arrbytGroups)) For j = 0 To UBound(arrbytGroups) arrstrGroupSids(j) = OctetToHexStr(arrbytGroups(j)) Set objGroup = GetObject("LDAP:// & ">") objGroupList(objGroup.sAMAccountName) = True Next Set objGroup = Nothing End Sub '------------------------------------------------------------ I have stripped out loads from this script as it is part of a whole logon. I think everything you need is there. BoX Hope this helps Edit:--- you say you dont need to deploy printers, but that is what the question looks like. However this is a way of runnong part of the script based on user or computer groups BoX Edited October 6, 2010 by box_l read additional posts
browolf Posted October 6, 2010 Posted October 6, 2010 messy but you could do dsget computer "cn=%computername%,ou=computers,dc=etc,dc=etc" -memberof | find "groupname" if %errorlevel%=0 rundll32 printui.dll,PrintUIEntry /y /n "\\KP-Print\V213Mono" assuming your ad structure can handle it, you would have to have 2 lines per printer assignment.
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