472,358 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

problems creating a user in Active directory

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

Jun 12 '07 #1
1 1871
Ysgrifennodd Carlettus:
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
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
Jun 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mario Rodriguez | last post by:
Hi people. I have a problem adding users to Win2003 active directory programatically. When I execute my app throws the following exception: .................The specified directory service...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
2
by: mb12036 | last post by:
All- Having a problem installing a DB2 client on a machine running AIX version 5.0. Client appeared to install one time succesfully, then was uninstalled and a reinstall was attempted. For...
1
by: B. Zuidgeest | last post by:
I use C# to connect a database with student information directly to the Active Directory (2003). This means that as the student is enlisted an account and mailbox is created in the active...
0
by: J'son | last post by:
Guys, I need to build a web intranet application that can automatically create a user account when a new user registers on the site. The user account will be on the web server, member of the...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
2
by: Adam Witney | last post by:
Forwarding to the mailing list, as I don't know how to fix it.... ------ Forwarded Message From: Henning Klein <kleinh@rz.uni-potsdam.de> Date: Tue, 22 Jun 2004 22:09:08 +0200 To:...
8
by: BARTKO, Zoltán | last post by:
Hello, folks, I am trying to install pgsql8 on winxp. I tried first to install "as is" with pginstaller beta2-dev3, no luck, it froze, switched off Nod32, froze a little later, ran through the...
1
by: Joanne | last post by:
I'm wondering if anyone has come across this problem before - it's got me stumped (but then again, I don't know a great deal about AD!!) In a specific set of circumstances, we get a really useful...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.