Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

problems creating a user in Active directory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlettus - 12 Jun 2007 09:05 GMT
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
%>
Peter Bradley - 14 Jun 2007 19:46 GMT
Ysgrifennodd Carlettus:
> Dear All,
> sorry but I'm not sure if this is the right place to post my problem.
[quoted text clipped - 6 lines]
> Thank you for your support
> Carlo

There's microsoft.public.adsi.general newsgroup that you might like to
try.  This book (by a regular contributor to the newsgroup) is also
excellent - but only if you're using .NET.

HTH

Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.