Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding a user in Active Directory

Posted on 2004-04-16
9
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

722 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