473,554 Members | 3,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.AccountDis abled = 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



On Error Resume Next
'/// Variable Declarations

Dim User, Container, TargetContainer , sObjectCommonNa me, FirstName, LastName
Dim ObjectSAMName, InitialPassword , sUserPrincipalN ame, sUserPath, sFullName
Dim szUsername, szPassword, sOU, intUAC



sOU = Request.Form("n ame_ou")

'/// Assign variable values from the form

TargetContainer = "LDAP://OU=" & sOU &
szUsername = (Request.Server Variables("AUTH _USER"))
szPassword = Request.Form("p assword")
ObjectSAMName = Request.Form("a cc_logname")
InitialPassword = Request.Form("a cc_passwd")
FirstName = Request.Form("a cc_firstname")
LastName = Request.Form("a cc_lastname")
sObjectCommonNa me = LastName & "\, " & FirstName
sFullName = FirstName & " " & LastName
sUserPath = "LDAP://CN=" & sObjectCommonNa me & ",OU=" & sOU &

Set obj1 = GetObject(Targe tContainer)

'/// check if a user already exists

Dim strUserName
CheckForUser(Ob jectSAMName)
Sub CheckForUser(sa mAccountName)
strUserName = samAccountName

'/// Create, configure, and open ADO Connection object

Set objConnection = CreateObject("A DODB.Connection ")
objConnection.O pen "Provider=ADsDS OObject;"

Set objCommand = CreateObject("A DODB.Command")
objCommand.Acti veConnection = objConnection

objCommand.Comm andText = _
"<LDAP://OU=" & sOU &
",OU=wss_ou,OU= NAME1,DC=NAME2, DC=NAME3,DC=ORG >;(&(objectCate gory=User)" & _
"(samAccountNam e=" & strUserName & "));samAccountN ame;subtree"
Set objRecordSet = objCommand.Exec ute

If objRecordset.Re cordCount = 0 Then
'/// If the user does not exist, then create the account and
'/// populates the object's properties

Set User = obj1.Create("us er", "CN=" & sObjectCommonNa me)
User.Put "sAMAccountName ", ObjectSAMName
User.Put "givenName" , FirstName
User.Put "sn", LastName
User.Put "userPrincipalN ame", ObjectSAMName
User.Put "DisplayNam e", LastName & " " & FirstName
User.Put "Descriptio n", "Sharepoint use only: created by " & szUsername

'/// Sets the password and enables the account

intUAC = User.Get("userA ccountControl")
User.Put "userAccountCon trol", ADS_UF_DONT_EXP IRE_PASSWD

User.SetPasswor d InitialPassword
User.AccountDis abled = False

If Err.Number = 0 Then

'/// If no errors occur, it displays a success screen

Response.redire ct "result.asp "

'/// If an error occurs, it displays an error message

Response.redire ct "result_no. asp"
End If

End If

'/// Clean up

objConnection.C lose

End Sub

Jun 12 '07 #1
1 1958
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.AccountDis abled = 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
There's microsoft.publi c.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.

Jun 14 '07 #2

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

Similar topics

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 attribute or value does not exist........... Exactly the same code works fine on my win2000 active directory. My app include the use of the...
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
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 some reasons, it does not complete the reinstall. See the status report from the GUI installer at the end of this note. Errors are towards the...
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 directory. Creating users is flawless en mailbox creating went perfect against a single exhange server using code from KB article 313114 of which part is...
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 guests group (or some other limited group), and get read permissions to a special folder. I've tried playing with Active Directory on my local box,...
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 updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not...
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: awitney@sghms.ac.uk Subject: problems with installing postgres hi,
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 list of services, switched off anything that seemed to be a firewall, no luck. So I compiled beta3 with mingw, installed, and now initdb keeps...
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 'Unknown Error' generated from the DirectoryEntry.Bind method using c# .net (framework v1.1). I've tried a few things to see if it makes any...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.