Solved

Adding a user in Active Directory

Posted on 2004-04-16
9
304 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

10 Experts available now in Live!

Get 1:1 Help Now