msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Active Directory

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise
Author Message
Ruslan Shlain



Joined: 04 Oct 2007
Posts: 1

PostPosted: Tue Sep 09, 2003 1:17 pm    Post subject: Active Directory Reply with quote

I have a small function that creates a user in AD. Its doing it fine at the
root, but when i try to create a user with in existing Org Unit it tells me
that there is no such bject on the server. I tryed everything and cant come
uo with the answer. Please help. Is there a setting or is there something i
do wrong? here is my code.

Public Function createUser(ByVal strFirstName As String, ByVal strLastName
As String, ByVal strUsername As String, ByVal strPassword As String, ByVal
strOrgUnit As String) As Boolean

Dim objContainer As IADsContainer
Dim objNewUser As IADsUser
Dim strFullPath As String
Dim objUser As IADsUser
Dim strLDAPServer As String
Dim strLDAPDomain As String
Dim strNTDomain As String
Dim strFullName As String
Dim strUserContainer As String
Dim flag
Dim newFlag

On Error GoTo errorCreateUser

Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

strFullPath = LDAP://RUSLAN/OU=WHATEVER,OU=DEV,DC=SHLAIN,DC=COM

Set objContainer = GetObject(strFullPath)

'Add the user
strFullName = strFirstName & " " & strLastName
Set objUser = objContainer.Create("user", "cn=" & strFullName)
objUser.Put "samAccountName", strUsername
objUser.Put "userPrincipalName", strUsername
objUser.Put "distinguishedName", strUsername
objUser.SetInfo

objUser.AccountDisabled = False
objUser.SetPassword ("password")
objUser.FirstName = strFirstName
objUser.LastName = strLastName
objUser.SetInfo

flag = objUser.Get("userAccountControl")
newFlag = flag Or ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", newFlag
objUser.SetInfo

createUser = True
Exit Function

errorCreateUser:
gv_strErrorMessage = "Error in createUser(): " & CStr(Err.Number) & " -
" & CStr(Err.Description) & " at " & CStr(Err.Source)
LogMessage (gv_strErrorMessage)
Exit Function

End Function

Archived from group: microsoft>public>vb>enterprise
Back to top
View user's profile Send private message
Paul Clement



Joined: 04 Oct 2007
Posts: 1560

PostPosted: Tue Sep 09, 2003 9:03 pm    Post subject: Re: Active Directory Reply with quote

On Tue, 9 Sep 2003 09:17:01 -0500, "Ruslan Shlain"
wrote:

¤ I have a small function that creates a user in AD. Its doing it fine at the
¤ root, but when i try to create a user with in existing Org Unit it tells me
¤ that there is no such bject on the server. I tryed everything and cant come
¤ uo with the answer. Please help. Is there a setting or is there something i
¤ do wrong? here is my code.
¤
¤ Public Function createUser(ByVal strFirstName As String, ByVal strLastName
¤ As String, ByVal strUsername As String, ByVal strPassword As String, ByVal
¤ strOrgUnit As String) As Boolean
¤
¤ Dim objContainer As IADsContainer
¤ Dim objNewUser As IADsUser
¤ Dim strFullPath As String
¤ Dim objUser As IADsUser
¤ Dim strLDAPServer As String
¤ Dim strLDAPDomain As String
¤ Dim strNTDomain As String
¤ Dim strFullName As String
¤ Dim strUserContainer As String
¤ Dim flag
¤ Dim newFlag
¤
¤ On Error GoTo errorCreateUser
¤
¤ Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
¤
¤ strFullPath = LDAP://RUSLAN/OU=WHATEVER,OU=DEV,DC=SHLAIN,DC=COM
¤
¤ Set objContainer = GetObject(strFullPath)

The distinguished name to the OU path (container) doesn't look right. Shouldn't
it be:

strFullPath = LDAP://OU=WHATEVER,OU=DEV,DC=SHLAIN,DC=COM

I'm assuming the WHATEVER is the OU under which you want to create the user?

If RUSLAN is an OU then it should be:

strFullPath = LDAP://OU=RUSLAN,OU=WHATEVER,OU=DEV,DC=SHLAIN,DC=COM


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group