Populating Active Directory with vb.net

Posted on 2003-03-11
Medium Priority
Last Modified: 2007-12-19
I need to be able to create, delete and update details including changing password in active directory from a VB.net application.  This application will running on a machine that is not part of the domain so there for I will need to bind as administrator or similar to do any account creation/maintenance

From what I understand I need something like this...

dim ou as object

ou = GetObject("LDAP://myDomain/CN=users, DC=myCompany,DC=com",userName, password)
set Set usr = ou.Create("user", "CN=test user")
usr.Put "samAccountName", "testuserid"

usr.Put "sn", "User"
usr.Put "givenName", "Test"

usr.SetPassword "guess_it"    

... but I can not seem to get it to work.
Does anyone have any ideas?

Question by:philipw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 23

Expert Comment

ID: 8116653
What is the error you are getting?
Is the user account getting created or not? Or is it getting created in "inactive" state?

Author Comment

ID: 8116711
Exception ERROR System.Exception: Cannot create ActiveX component. at Microsoft.VisualBasic.Interaction.GetObject(String PathName, String Class)
at AD_Population.Main.Add_User(String operation, String request, String client) in AD_Population\Main.vb:line 149

The error is generated the line
ou = GetObject("LDAP://myDomain/CN=users, DC=myCompany,DC=com",userName, password)

So it doesn't get to the create user part

LVL 23

Accepted Solution

naveenkohli earned 750 total points
ID: 8116811
Use System.DirectoryService namespace classes to get your AD stuff done. This will be more.Net centric way of doing it. Here is a link that may be of some help..

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


Author Comment

ID: 8117015
I'm getting close I can feel it!!
I now have

Dim cnEntry As DirectoryEntry
Dim dsUser As DirectoryEntry

cnEntry = New DirectoryEntry("LDAP://myDomain/CN=users, DC=myCompany,DC=com",userName, password)

it now fails on line ...
dsUser = cnEntry.Children.Add("sUserName", "user")
Exception ERROR System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_IsContainer()
   at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
   at System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName)
LVL 23

Expert Comment

ID: 8118597

Author Comment

ID: 8123072
All working now.  The problem was that for some reason it will not work when the application is run from the IDE.  Run the exe and all works as it should.

Thanks for your help.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question