WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Group Membership Checking

 Keywords:  

Question:

How can the ADSI group membership of a user be checked from, say, a logon script?

Answer:

This script has been "generisized" But if you look at the whole thing you can see how it works. With a John Doe example, the user path needs to be: LDAP://sysboomba/cn=Doe\, John,cn=Users,DC=sys,DC=boom,DC=ba This is the way the user actually exists in AD. When it searches AD for the user, it finds the user. And once the user has been found within AD, the user can then be tested for group membership.
;This UDF returns various sorts of user names.
;Username type 1 is used here. 

#DefineFunction GetUserNameEx(type)
  dll=StrCat(DirWindows(1),"secur32.dll")
  bbsize=1000
  bb=BinaryAlloc(bbsize)
  BinaryEodSet(bb,bbsize)
  bbs=BinaryAlloc(4)
  BinaryPoke4(bbs,0,bbsize)
  DllCall(dll,long:"GetUserNameExA",long:type,lpbinary:bb,lpbinary:bbs)
  retval=BinaryPeekStr(bb,0,bbsize)
  BinaryFree(bb)
  BinaryFree(bbs)
  Return(retval)
#EndFunction

UserNameAD = GetUserNameEx(1)    ; Get ADSI compatible user name
;UserName = wntGetUser(@default)  ; Get standard user name
;fullname=wntUserGetDat("\\SERVER1",UserName,"full_name")  ; get users full name for no reason

dsSetCredent("", "")

sUserPath = StrCat("LDAP://sysboomba/",UserNameAD)
sGroupPath = "LDAP://SEBDOM1/cn=WORKERS,OU=DEPARTMENT,OU=COMPANY,DC=sys,DC=boom,DC=ba"
If dsIsMemberGrp(sGroupPath,sUserPath) 
   IsMemberofWORKERSGroup  = @TRUE
Else
   IsMemberofWORKERSGroup =  @FALSE
EndIf

Article ID:   W15815
File Created: 2004:03:30:15:40:58
Last Updated: 2004:03:30:15:40:58