Solved

Adding a user in Active Directory

Posted on 2004-04-16
9
305 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
if form parameter is null redirect 2 53
Round to 2 decimal places 2 40
show region if a selection is made on a drop down menu 3 56
Want the count number from this QUery 2 38
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

930 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now