Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Stuck with VB.Net & ActiveDirectory Groups

Alright Im stuck Heres a 5 second overview

Im working in VB.Net ( 2.0 framework ) and Im creating an executable app that reads from a MySql database and updates our Active Directory LDAP database as needed Everything works except for adding a user to an AD group.

I know that I have to add the user to the group record (member) and NOT the group to the user record (MemberOf)

' ActiveGroup is predefined and is the samaccountname for the group
ADquery3 = "<LDAP://" & GlobalVar.strldapConnection & GlobalVar.strldapDomain & ">" & _
";(&(objectClass=*)(samaccountname=" & ActiveGroup & "))" & _
";ADsPath;SubTree"

ADcommand3.CommandText = ADquery3
ADrecordset3 = ADcommand3.Execute

Dim objUser3 As Object
objUser3 = GetObject(ADrecordset3.Fields("ADsPath").Value)

' ActiveUser is predefined and is the distinguished name of the user
objUser3.PutEX("member", LTrim(RTrim(CStr(ActiveUser))))

Error:
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

Am I going about this all wrong?
[1119 byte] By [bkettleh] at [2007-11-11 7:36:37]
# 1 Re: Stuck with VB.Net & ActiveDirectory Groups
What you need to do is add the user to a group object. I don't believe you can add a user to a group through the user object. The following should help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/adding_users_to_a_group.asp
pclement at 2007-11-11 21:48:47 >
# 2 Re: Stuck with VB.Net & ActiveDirectory Groups
Got it and it works - thanks!
bkettleh at 2007-11-11 21:49:53 >