EndFunc Posted April 17, 2009 Share Posted April 17, 2009 (edited) OK I'm trying to call this function from the AD functinos UDF and I just can't get it to work. What are the parameters that are entered to use the function. Anyone have an example of how to call this function. Not understanding the the ByRef. Also I don't want to use the default logged in user but specify a user. ; _ADGetUserGroups ; the currently logged on user is a member of. Returns an array of Full DNs of the Group names that the user is immediately a member of ; with element 0 containing the number of groups. ; $user - optional -- SamAccountName of a user, defaults to locally logged on user Func _ADGetUserGroups(ByRef $usergroups, $user = @UserName) Local $oUsr $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree" $objRecordSet = $objConnection.Execute($strQuery) ; Retrieve the FQDN for the logged on user $ldap_entry = $objRecordSet.fields(0).value $oUsr = _ADObjGet($ldap_entry) ; Retrieve the COM Object for the logged on user $usergroups = $oUsr.GetEx("memberof") $oUsr = 0 $count = UBound($usergroups) _ArrayInsert($usergroups, 0, $count) EndFunc ;==>_ADGetUserGroups Edited April 17, 2009 by EndFunc EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 17, 2009 Share Posted April 17, 2009 (edited) OK I'm trying to call this function from the AD functinos UDF and I just can't get it to work. What are the parameters that are entered to use the function. Anyone have an example of how to call this function. Not understanding the the ByRef. Also I don't want to use the default logged in user but specify a user. ; _ADGetUserGroups ; the currently logged on user is a member of. Returns an array of Full DNs of the Group names that the user is immediately a member of ; with element 0 containing the number of groups. ; $user - optional -- SamAccountName of a user, defaults to locally logged on user Func _ADGetUserGroups(ByRef $usergroups, $user = @UserName) Local $oUsr $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree" $objRecordSet = $objConnection.Execute($strQuery); Retrieve the FQDN for the logged on user $ldap_entry = $objRecordSet.fields(0).value $oUsr = _ADObjGet($ldap_entry); Retrieve the COM Object for the logged on user $usergroups = $oUsr.GetEx("memberof") $oUsr = 0 $count = UBound($usergroups) _ArrayInsert($usergroups, 0, $count) EndFunc ;==>_ADGetUserGroups After 266 posts since March, 2007 you don't know what ByRef is for? ByRef means the variable given in the input parameter will be altered by the function. You cannot pass a literal string, it must be a previously declared variable which will be altered when used by the function: #include <Array.au3> Global $avGroups Global $sUser = "MyFunkyUser" _ADGetUserGroups($avGroups, $sUser) _ArrayDisplay($avGroups, "Groups") Internally to the function, whenever the local $usergroups is used, the global $avGroups gets modified "By Reference". Edited April 17, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
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