Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1966
  • Last Modified:

Populating Active Directory with vb.net

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?

  • 3
  • 3
1 Solution
What is the error you are getting?
Is the user account getting created or not? Or is it getting created in "inactive" state?
philipwAuthor Commented:
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

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..

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

philipwAuthor Commented:
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)
philipwAuthor Commented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now