473,395 Members | 1,987 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,395 software developers and data experts.

create user within active directory.

Hi,

I have code from the msdn to crate a user in an AD domain. I have set the
code and changed the necessary parameters for the ldap queries but was
wondering how i can execute this code on a button press. I can't put this
code within the button private sub of the button as i receive errors within
the code.

What do i need to do to start this off from the executed button?

The code is as follows..

lass CreateUser

'/ <summary>

'/ Create ADAM User.

'/ </summary>

<STAThread()> Shared Sub Main()

Dim objADAM As DirectoryEntry ' Binding object.

Dim objUser As DirectoryEntry ' User object.

Dim strDisplayName As String ' Display name of user.

Dim strPath As String ' Binding path.

Dim strUser As String ' User to create.

Dim strUserPrincipalName As String ' Principal name of user.

' Construct the binding string.

strPath = "LDAP://localhost:389/O=Fabrikam,C=US"

Console.WriteLine("Bind to: {0}", strPath)

' Get ADAM object.

Try

objADAM = New DirectoryEntry(strPath)

objADAM.RefreshCache()

Catch e As Exception

Console.WriteLine("Error: Bind failed.")

Console.WriteLine(" {0}", e.Message)

Return

End Try

' Specify User.

strUser = "CN=TestUser"

strDisplayName = "Test User"

strUserPrincipalName = "Te******@Fabrikam.Us"

Console.WriteLine("Create: {0}", strUser)

' Create User.

Try

objUser = objADAM.Children.Add(strUser, "user")

objUser.Properties("displayName").Add(strDisplayNa me)

objUser.Properties("userPrincipalName").Add( _

strUserPrincipalName)

objUser.CommitChanges()

Catch e As Exception

Console.WriteLine("Error: Create failed.")

Console.WriteLine(" {0}", e.Message)

Return

End Try

' Output User attributes.

Console.WriteLine("Success: Create succeeded.")

Console.WriteLine("Name: {0}", objUser.Name)

Console.WriteLine(" {0}", _

objUser.Properties("displayName").Value)

Console.WriteLine(" {0}", _

objUser.Properties("userPrincipalName").Value)

Return

End Sub 'Main

End Class 'CreateUser

thanks
Nov 21 '05 #1
0 1101

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

Similar topics

4
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
1
by: richb330 | last post by:
I'm trying to set up a program that will create a user account within active directory based on a number of parameters selected on a form. The following code should, i believe, create a user...
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...
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...
4
Chrisjc
by: Chrisjc | last post by:
Good evening, I was wondering if anyone knew of a way or something to help me out with an issue I been dealing with lately, I have several sites in an Active Directory environment across a WAN....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
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,...

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.