Page 1 of 1 1
Topic Options
#175557 - 2007-04-20 05:13 PM ComputerInGroup Cache?
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
Is there a way to boost the performance of the ComputerInGroup UDF? Is there a way (or a better option)to not have to query AD multiple times during the logon process? The computer group membership doesn't change during the logon process, so is there a way to cache the computer's memberships?

I'd like something similar to the way the InGroup function was updated w/ kix 4.x where the group-membership cache is stored in the registry hive of the current user and contains security-identifier-to-groupname mappings.

Thanks
Tylan

Top
#175558 - 2007-04-20 06:43 PM Re: ComputerInGroup Cache? [Re: tylan]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you look at the code used, you can see it doesn't actually pull all the groups, just the one you pass to the WinNT provider. Maybe you should look at fnInGroupAD() for ideas.
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=144167
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#175589 - 2007-04-23 07:19 PM Re: ComputerInGroup Cache? [Re: Les]
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
fnInGroupAD() doesn't seem much different, it's just using LDAP for the query.

Thanks anyways.

Top
#175594 - 2007-04-23 08:09 PM Re: ComputerInGroup Cache? [Re: tylan]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Your best bet may be to store the Computer's group membership in an array and reference the array instead of calling query based UDF's multiple times. This way you'll have a fresh (as of logon) collection of the computer's groups, but won't have to query AD everytime you want to check membership.
Top
#175595 - 2007-04-23 08:34 PM Re: ComputerInGroup Cache? [Re: Chris S.]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Something like...

 Code:
$groups = fnInGroup()

For Each $G in $Groups
   $G ?
Next



Get $

Function fnInGroup(Optional $bComputer)
    Dim $objSys,$objTarget,$aMemberOf,$sMemberOf,$i
    $objSys = CreateObject("ADSystemInfo")
    $objTarget = GetObject("LDAP://"+Iif($bComputer,$objSys.ComputerName,$objSys.UserName))
    $aMemberOf = $objTarget.GetEx("memberOf")
    Dim $aGroups[UBound($aMemberOf)]
    For Each $sMemberOf in $aMemberOf
      $aGroups[$i] = Split(Split($sMemberOf,"CN=")[1],",")[0]
      $i = $i + 1
    Next
     $fnInGroup = $aGroups
EndFunction

Top
#175987 - 2007-05-04 08:40 PM Re: ComputerInGroup Cache? [Re: Chris S.]
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
How would I use your code to map printers based on group membership?
Top
#175989 - 2007-05-04 08:48 PM Re: ComputerInGroup Cache? [Re: tylan]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Read through the entire thread. I thnk it has what you are looking for...

Create AD Global Groups for printer objects

More related discussion of groups and printers:
Primary computer group membership


Edited by Howard Bullock (2007-05-04 09:03 PM)
Edit Reason: Added content
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#175993 - 2007-05-04 09:20 PM Re: ComputerInGroup Cache? [Re: Howard Bullock]
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
I think I was over thinking this...
 Code:
$groups = fnInGroup(@WKSTA)

For Each $Group in $Groups
   IF $Group = "PARSTDCOMPUTERS"
	?"Do Stuff"
   ENDIF
   IF $Group = "BUSINESS_OFFICE_PRINTER_COMPUTERS"
	?"Do More stuff"
   ENDIF	

Next



Get $

Function fnInGroup(Optional $bComputer)
    Dim $objSys,$objTarget,$aMemberOf,$sMemberOf,$i
    $objSys = CreateObject("ADSystemInfo")
    $objTarget = GetObject("LDAP://"+Iif($bComputer,$objSys.ComputerName,$objSys.UserName))
    $aMemberOf = $objTarget.GetEx("memberOf")
    Dim $aGroups[UBound($aMemberOf)]
    For Each $sMemberOf in $aMemberOf
      $aGroups[$i] = Split(Split($sMemberOf,"CN=")[1],",")[0]
      $i = $i + 1
    Next
     $fnInGroup = $aGroups
EndFunction


So, this code would be more efficient than checking AD 25+ time for computer group membership?

Top
#175994 - 2007-05-04 09:39 PM Re: ComputerInGroup Cache? [Re: tylan]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
A SELECT...CASE...ENDSELECT would be more efficient. Once a match is found, the other conditions are not checked. Place the largest group at the top and add them in descending order by members.

Edited by Howard Bullock (2007-05-04 09:40 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#175995 - 2007-05-04 09:45 PM Re: ComputerInGroup Cache? [Re: Howard Bullock]
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
Cool. Will do.

Since no one ever corrected me... I'm assuming that the ComputerInGroup UDF is not efficient if you are going to run it 20 - 30 times in a row.

Top
#175997 - 2007-05-04 09:52 PM Re: ComputerInGroup Cache? [Re: tylan]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What about Chris' suggestion?
 Originally Posted By: Chris S.
Your best bet may be to store the Computer's group membership in an array and reference the array instead of calling query based UDF's multiple times. This way you'll have a fresh (as of logon) collection of the computer's groups, but won't have to query AD everytime you want to check membership.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#175998 - 2007-05-04 10:11 PM Re: ComputerInGroup Cache? [Re: Les]
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
Oh... I guess he did confirm that running the UDF multiples times was inefficient.
Top
#176001 - 2007-05-04 11:59 PM Re: ComputerInGroup Cache? [Re: tylan]
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
Chris,
Why did you use LDAP for your code? Instead of ADSI? Is ADSI a quicker lookup?


Edited by tylan (2007-05-08 03:17 PM)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (mole) and 1300 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.088 seconds in which 0.057 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org