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