473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Howto Create Active Directory Account

Hello,

For those who are interested in creating Account in Active Directory here is
some code I used.

ublic Function create_user(ByVal firstname As String, ByVal lastname As
String, _
ByVal Address As String, ByVal pwd As String)
Try
Dim MyRoot As DirectoryServices.DirectoryEntry
Dim MyUser As DirectoryServices.DirectoryEntry
Dim MySearcher As DirectorySearcher
Dim MyResult As SearchResult
Dim Loginname As String
Dim x As Integer

x = 1
Loginname = Replace(lastname, " ", "")
MyRoot = New
DirectoryServices.DirectoryEntry("LDAP://ASDVM01.milkyway.com",
"milkyway\administrator", "knowledge")
'create search option(looks if the user already exist)
MySearcher = New DirectorySearcher(MyRoot)
MySearcher.Filter = "(userPrincipalName=" & Loginname & ")"
MyResult = MySearcher.FindOne()

Do While Not MyResult Is Nothing
If x <= Len(firstname) Then
Loginname = Replace(lastname, " ", "") & "-" &
Left(firstname, x)

Else
Loginname = Replace(lastname, " ", "") & "-" & firstname
& CStr(x - Len(firstname))
MsgBox(Loginname)
End If
MySearcher.Filter = "(userPrincipalName=" & Loginname & ")"
MyResult = MySearcher.FindOne()
x = x + 1
Loop
'add user properties to the new user
MyUser = MyRoot.Children.Add("CN=" & Loginname, "user")
MyUser.Properties("GivenName").Add(firstname)
MyUser.Properties("sn").Add(lastname)
MyUser.Properties("DisplayName").Add(firstname & " " & lastname)
MyUser.Properties("name").Add(Loginname)
MyUser.Properties("sAMAccountName").Add(Loginname)
MyUser.Properties("userPrincipalName").Add(Loginna me &
"@milkyway.com")
MyUser.Properties("streetaddress").Add(Address)
MyUser.Properties("mail").Add(firstname & "." &
Replace(lastname, " ", "") & "@milkyway.com")
MyUser.CommitChanges()

MyUser.NativeObject.AccountDisabled = False
MyUser.CommitChanges()
MyUser.Invoke("SetPassword", pwd)
MyUser.CommitChanges()

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

this code checks if the user already exist if so it will create an new
account with lastname + fist char of the firstname.

Hopefully this code will help someone

Have fun!!!
Martijn
Nov 20 '05 #1
0 1190

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

Similar topics

2
by: Jay Chan | last post by:
We have just installed a SQL Server 2000 (SP 3A) onto a computer that has Windows-2003 Server on it. Now, we cannot get access to that database server from other computers. Seem like this may be an...
1
by: Publickey | last post by:
Hi, I am having trouble setting the user's cn value using VB .NET 2002 while creating a new user account. The code is as below: ***********************Start of code****************************...
2
by: Keith Jakobs, MCP | last post by:
Greetings: I had seen several posts around the Internet about this issue from a few months back, but have been unable to find a resolution ... I have a user who is trying to get started with...
6
by: varkey.mathew | last post by:
Dear all, Bear with me, a poor newbie(atleast in AD).. I have to authenticate a user ID and password for a user as a valid Active Directory user or not. I have created the IsAuthenticated...
0
by: jakobsgaard | last post by:
It is possible to Map a certificate to a Active Directory User Account from DotNet? Please provide an example. Best regards, Ejnar Jakobsgaard...
3
by: Lucky | last post by:
Hi guys, after long long time. i'm back again with another problem. this time i think the problem is very very interesting and i really need you help on this. i'm trying to connect to the...
2
by: Michael | last post by:
Hello, I've created an ASP web page where users in our organization can create Active Directory computer accounts. The web page is running on a Server 2003 SP1 IIS 6 installation. The...
5
by: Michael | last post by:
Hello, I've created an ASP web page where users in our organization can create Active Directory computer accounts. The web page is running on a Server 2003 SP1 IIS 6 installation. The...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.