C
Carlettus
Dear All,
sorry but I'm not sure if this is the right place to post my problem.
I was using the following asp code to create users in Active Directory.
Suddenly, and I don't know the reason, users are created but the account is
disabled (see the flag User.AccountDisabled = False ).
There is also another problem even if the user does not exist , the
application returns to me with the message that the user already exist.
Thank you for your support
Carlo
---------------------------------------------------
<%
On Error Resume Next
'/// Variable Declarations
Dim User, Container, TargetContainer, sObjectCommonName, FirstName, LastName
Dim ObjectSAMName, InitialPassword, sUserPrincipalName, sUserPath, sFullName
Dim szUsername, szPassword, sOU, intUAC
Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
sOU = Request.Form("name_ou")
'/// Assign variable values from the form
TargetContainer = "LDAP://OU=" & sOU &
",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG"
szUsername = (Request.ServerVariables("AUTH_USER"))
szPassword = Request.Form("password")
ObjectSAMName = Request.Form("acc_logname")
InitialPassword = Request.Form("acc_passwd")
FirstName = Request.Form("acc_firstname")
LastName = Request.Form("acc_lastname")
sObjectCommonName = LastName & "\, " & FirstName
sFullName = FirstName & " " & LastName
sUserPath = "LDAP://CN=" & sObjectCommonName & ",OU=" & sOU &
",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG"
Set obj1 = GetObject(TargetContainer)
'/// check if a user already exists
Dim strUserName
CheckForUser(ObjectSAMName)
Sub CheckForUser(samAccountName)
strUserName = samAccountName
'/// Create, configure, and open ADO Connection object
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://OU=" & sOU &
",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG>;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));samAccountName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
'/// If the user does not exist, then create the account and
'/// populates the object's properties
Set User = obj1.Create("user", "CN=" & sObjectCommonName)
User.Put "sAMAccountName", ObjectSAMName
User.Put "givenName", FirstName
User.Put "sn", LastName
User.Put "userPrincipalName", ObjectSAMName
User.Put "DisplayName", LastName & " " & FirstName
User.Put "Description", "Sharepoint use only: created by " & szUsername
User.SetInfo
'/// Sets the password and enables the account
intUAC = User.Get("userAccountControl")
User.Put "userAccountControl", ADS_UF_DONT_EXPIRE_PASSWD
User.SetInfo
User.SetPassword InitialPassword
User.AccountDisabled = False
User.SetInfo
If Err.Number = 0 Then
'/// If no errors occur, it displays a success screen
Response.redirect "result.asp"
Else
'/// If an error occurs, it displays an error message
Response.redirect "result_no.asp"
End If
Else
End If
'/// Clean up
objConnection.Close
End Sub
%>
sorry but I'm not sure if this is the right place to post my problem.
I was using the following asp code to create users in Active Directory.
Suddenly, and I don't know the reason, users are created but the account is
disabled (see the flag User.AccountDisabled = False ).
There is also another problem even if the user does not exist , the
application returns to me with the message that the user already exist.
Thank you for your support
Carlo
---------------------------------------------------
<%
On Error Resume Next
'/// Variable Declarations
Dim User, Container, TargetContainer, sObjectCommonName, FirstName, LastName
Dim ObjectSAMName, InitialPassword, sUserPrincipalName, sUserPath, sFullName
Dim szUsername, szPassword, sOU, intUAC
Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
sOU = Request.Form("name_ou")
'/// Assign variable values from the form
TargetContainer = "LDAP://OU=" & sOU &
",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG"
szUsername = (Request.ServerVariables("AUTH_USER"))
szPassword = Request.Form("password")
ObjectSAMName = Request.Form("acc_logname")
InitialPassword = Request.Form("acc_passwd")
FirstName = Request.Form("acc_firstname")
LastName = Request.Form("acc_lastname")
sObjectCommonName = LastName & "\, " & FirstName
sFullName = FirstName & " " & LastName
sUserPath = "LDAP://CN=" & sObjectCommonName & ",OU=" & sOU &
",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG"
Set obj1 = GetObject(TargetContainer)
'/// check if a user already exists
Dim strUserName
CheckForUser(ObjectSAMName)
Sub CheckForUser(samAccountName)
strUserName = samAccountName
'/// Create, configure, and open ADO Connection object
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://OU=" & sOU &
",OU=wss_ou,OU=NAME1,DC=NAME2,DC=NAME3,DC=ORG>;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));samAccountName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
'/// If the user does not exist, then create the account and
'/// populates the object's properties
Set User = obj1.Create("user", "CN=" & sObjectCommonName)
User.Put "sAMAccountName", ObjectSAMName
User.Put "givenName", FirstName
User.Put "sn", LastName
User.Put "userPrincipalName", ObjectSAMName
User.Put "DisplayName", LastName & " " & FirstName
User.Put "Description", "Sharepoint use only: created by " & szUsername
User.SetInfo
'/// Sets the password and enables the account
intUAC = User.Get("userAccountControl")
User.Put "userAccountControl", ADS_UF_DONT_EXPIRE_PASSWD
User.SetInfo
User.SetPassword InitialPassword
User.AccountDisabled = False
User.SetInfo
If Err.Number = 0 Then
'/// If no errors occur, it displays a success screen
Response.redirect "result.asp"
Else
'/// If an error occurs, it displays an error message
Response.redirect "result_no.asp"
End If
Else
End If
'/// Clean up
objConnection.Close
End Sub
%>