Solved

Adding a user in Active Directory

Posted on 2004-04-16
9
307 Views
Last Modified: 2007-12-19
Hello,

I'm having a problem creating a user in active directory when setting the password. Everything else gets created just fine when i take out the code to set the password, but when i put that back in I get an error. I'm not sure what the problem could be. Any help we be appreciated. Here is the code:

<%
UserAccount = request.form("UserAccount")
FirstName = request.Form("FirstName")
LastName = request.Form("LastName")
Password = request.Form("Password")

FullName = FirstName & " " & LastName


set objADsOpenDSObject = GetObject("LDAP:")

strParentDN = "ou=Test OU,dc=<domainname>,dc=local"

strUser = ("LDAP://" & strParentDN)

Set objAds = objADsOpenDSObject.OpenDSObject(strUser , UserName, Password, ADS_USE_ENCRYPTION)



UserAccount = UserAccount + <Domain>

' Create the object in the container using the full user name
Set adsUser = objAds.Create("user", "cn=" + FullName)

' Set the down-level account name for the user (<20 characters)
adsUser.Put "sAMAccountName", FullName

' Set the UPN for the user
adsUser.Put "userPrincipalName", UserAccount


' Update server with required properties
adsUser.SetInfo



' Use IADsUser properties to set other pieces of data
' Refresh the local property cache with new user info
adsUser.GetInfo

' Set the user password.  
adsUser.SetPassword Password----------right here is where I get the problem

' Require the user to change password on login
'adsUser.Put "pwdLastSet", 0

' Enable the account (the default when created is disabled)
adsUser.AccountDisabled = False

' Set the display name of the user
adsUser.FullName = FullName

' Set name information of the user
adsUser.FirstName = FirstName
adsUser.LastName = LastName

adsUser.SetInfo


Set adsUser = Nothing
set objAds = nothing


%>

0
Comment
Question by:spheretechinc
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 7

Expert Comment

by:ramesh12
ID: 10843481
Try changing the variable password to another name and see. I am not sure but take a look at this url the way they are setting

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20633656.html?query=active+directory&searchType=topic
0
 

Author Comment

by:spheretechinc
ID: 10843910
Thanks for the quick response. The variable is not the problem though because if i try to pass it without using a variable it still doesn't work. I can also get this exact code to work using vbscript it's just doesn't work when i try to do it through asp pages.
0
 
LVL 7

Expert Comment

by:TheKenman
ID: 10849249
I'm not sure why that's not working either, although I would have the same reservations for using 'password' as a variable name.

Anyways, here's the code I use; it's a slightly older technique, but it still might help you:


Function addUser(strUser,strDomain,strFullName,strPassword,strDesc)
   On Error Resume Next
   Dim Domain,User
   Set Domain = Getobject("WinNT://" & strDomain)
   Set User = Domain.Create("User",strUser)
   User.SetInfo
   If Err <> 0 then ' User already exists
      addUser = strUser & " already exists!!<BR>Aborting..."
      Exit Function
   End If
   User.FullName = strFullName
   User.Description = strDesc
   call User.SetPassword(strPassword)
   User.SetInfo
   If Err <> 0 then ' error setting info
      addUser = "Error setting fullname, description, or pw for:<b> " & strDomain & " \" & strUser & "</b>, but user was still created."
      Exit Function
   End If
   Set User = Nothing
   Set Domain = Nothing
End Function
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:spheretechinc
ID: 10849995
I agree with you about the variable for password and have chagned that. I will give your code a try and see if that works. Another quick question for you, does the asp pages have to be ran on a domain controller or does it matter? Thank you for your help.
0
 

Author Comment

by:spheretechinc
ID: 10903460
Well I answered my own question
0
 
LVL 7

Accepted Solution

by:
TheKenman earned 500 total points
ID: 10903971
How? Did you try my code?
0
 

Author Comment

by:spheretechinc
ID: 10907767
Well, actually for somew reason when i used

objAds.changepassword "", <newpasswprd>

that worked. I have yet to get the set password command to work but it let me set the password using the changepassword command.
0
 
LVL 2

Expert Comment

by:shibu020500
ID: 12071034
Don't know if you were able to solve the problem:
Here is what you can do , works for me,

objAds.Put "userPassword", strPassword

objAds.SetPassword strpassword
objAds.setinfo

-Shibu.
0
 
LVL 2

Expert Comment

by:shibu020500
ID: 12071046
Addendum:

instead of strpassword , you may use password

-Shibu
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JQuery Date Time picker not showing 29 131
SQL Filter Question 8 83
How to get statistic's from a competitors website?! 1 104
Diminish Pop-up  in 3 seconds 7 21
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question