473,834 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al firstname As String, ByVal lastname As
String, _
ByVal Address As String, ByVal pwd As String)
Try
Dim MyRoot As DirectoryServic es.DirectoryEnt ry
Dim MyUser As DirectoryServic es.DirectoryEnt ry
Dim MySearcher As DirectorySearch er
Dim MyResult As SearchResult
Dim Loginname As String
Dim x As Integer

x = 1
Loginname = Replace(lastnam e, " ", "")
MyRoot = New
DirectoryServic es.DirectoryEnt ry("LDAP://ASDVM01.milkywa y.com",
"milkyway\admin istrator", "knowledge" )
'create search option(looks if the user already exist)
MySearcher = New DirectorySearch er(MyRoot)
MySearcher.Filt er = "(userPrincipal Name=" & Loginname & ")"
MyResult = MySearcher.Find One()

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

Else
Loginname = Replace(lastnam e, " ", "") & "-" & firstname
& CStr(x - Len(firstname))
MsgBox(Loginnam e)
End If
MySearcher.Filt er = "(userPrincipal Name=" & Loginname & ")"
MyResult = MySearcher.Find One()
x = x + 1
Loop
'add user properties to the new user
MyUser = MyRoot.Children .Add("CN=" & Loginname, "user")
MyUser.Properti es("GivenName") .Add(firstname)
MyUser.Properti es("sn").Add(la stname)
MyUser.Properti es("DisplayName ").Add(firstnam e & " " & lastname)
MyUser.Properti es("name").Add( Loginname)
MyUser.Properti es("sAMAccountN ame").Add(Login name)
MyUser.Properti es("userPrincip alName").Add(Lo ginname &
"@milkyway.com" )
MyUser.Properti es("streetaddre ss").Add(Addres s)
MyUser.Properti es("mail").Add( firstname & "." &
Replace(lastnam e, " ", "") & "@milkyway.com" )
MyUser.CommitCh anges()

MyUser.NativeOb ject.AccountDis abled = False
MyUser.CommitCh anges()
MyUser.Invoke(" SetPassword", pwd)
MyUser.CommitCh anges()

Catch ex As Exception
MsgBox(ex.Messa ge)
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 1211

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

Similar topics

2
2133
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 issue with Active Directory. Our network consists of Windows-2000 Servers (SP 4) and Windows-2000 workstations and Windows-XP workstations. We also have SQL Server 2000 (SP2) in three Windows-2000 servers. All work fine. Recently, we get a...
1
3049
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**************************** Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://" + ldapStr) Dim NewUser As DirectoryEntry = enTry.Children.Add("CN=" & sAMAccountName, "User") NewUser.Properties("sAMAccountName").Value = sAMAccountName...
2
3125
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 Visual Studio.NET 2003. We have uninstalled and reinstalled the Product.... then we did a complete cleanout of development products, re-installed IIS, and reinstalled JUST Visual Studio.NET 2003 with Framework 1.1 (no more 2002 edition or...
6
2471
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 function exactly as outlined in the below link. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT02.asp
0
2747
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 ------------------------------------------------- To map a certificate to a user account Open Active Directory Users and Computers.
3
11318
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 Active Directory. for that i've added one linked server to connect to the active directory. and then query like this: adding linked server:
2
5365
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 Exchange System Manager is running on the web server and Exchange SP2 has been installed. The web page uses ADSI code to create a user, and then CDO code to create
5
4878
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 Exchange System Manager is running on the web server and Exchange SP2 has been installed. The IIS site is configured with Basic Authentication and users are prompted to enter their Active Directory credentials when connecting to the site.
18
23796
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 code/examples? Thanks in advance, Arthur
0
9796
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9643
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10790
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10545
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9329
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7755
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5624
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3976
muto222
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.