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

Working with ADSI

I am trying to write a program in VB.NET to work with Active Directory user accounts in my Win2K domain. I found sample code as shown below but when I add it to a project it says "Type IADsContainer is not defined" and "Type IADsUser is not defined". What is wrong? Am I missing a reference or something else?
Example: Creating a User Object (Visual Basic)

Dim Container as IADsContainer
Dim NewUser as IADsUser
‘ Bind to the known container.
Set Container = GetObject("WinNT://MSFT")

‘ Create the new Active Directory Service Interfaces User.
Set NewUser = Container.Create("User", "Jane")

‘ Set Jane’s password.
NewUser.AccountRestrictions.SetPassword("Argus")

‘ Complete the operation to create the object in the directory.
NewUser.SetInfo

Jul 21 '05 #1
2 3492
Don't use the WinNT provider when binding to a AD domain.
And you should use the System.DirectoryServices namespace classes, the
encapsulate the COM/ADSI functionality.
Check the MSDN docs for details and samples.

Willy.
"Dan Varozza" <an*******@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I am trying to write a program in VB.NET to work with Active Directory user accounts in my Win2K domain. I found sample code as shown below but
when I add it to a project it says "Type IADsContainer is not defined" and
"Type IADsUser is not defined". What is wrong? Am I missing a reference or
something else?

Example: Creating a User Object (Visual Basic)

Dim Container as IADsContainer
Dim NewUser as IADsUser
' Bind to the known container.
Set Container = GetObject("WinNT://MSFT")

' Create the new Active Directory Service Interfaces User.
Set NewUser = Container.Create("User", "Jane")

' Set Jane's password.
NewUser.AccountRestrictions.SetPassword("Argus")

' Complete the operation to create the object in the directory.
NewUser.SetInfo

Jul 21 '05 #2
>I found sample code as shown below but when I add it to a project it says "Type IADsContainer is not defined" and
"Type IADsUser is not defined". What is wrong? Am I missing a reference or something else?


Yes - you didn't add a reference to the COM "Active Ds Type Library"
object to your project - but you don't really need to either.

Instead, use the System.DirectoryServices namespace and its classes.

And as Willy also pointed out, dump the WinNT provider - use LDAP
instead (since only LDAP knows about the OU hierarchies that are the
cornerstone of any AD system).

So your code would look something like that (it's in C#, since I'm not
intimiately familiar with the VB syntax, but you should be able to
convert it easily):

// set up container's LDAP path
string sContainerPath = "LDAP://cn=Users,dc=fabrikam,dc=com");

// bind to it
DirectoryEntry deCtr = new DirectoryEntry(sContainerPath);

// create new user, set sAMAccountName (mandatory)
DirectoryEntry deUser = deCtr.Children.Add("cn=Jane Doe", "user");
deUser.Properties["samAccountName"].Value = "Jane_Doe";

// save changes to AD store - you ned to do this *BEFORE*
// you set the password!
deUser.CommitChanges();

// set password
deUser.Invoke("SetPassword", new object[] {"secret"});

That should do.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #3

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

Similar topics

6
by: Miguel Orrego | last post by:
Hi, I have found some code that authenticates users agains a domain using ADSI. I then redirect to another page and pass the username they have entered as a string. However, it would be nice to...
4
by: Akhlaq Khan | last post by:
we are developing an intranet application (web based) which needs to detect the logged in user ID of the user hitting the website. the intranet is huge and based on win2k active directory (around...
1
by: Ryan Ritten | last post by:
I was wondering if anyone knew how (or if it's even possible) to cache the results of an ADSI call in asp for a longer period of time. Basically what I am doing is I have a website that loads the...
2
by: Enigma Webmaster | last post by:
Hi All, We've written a couple of functions which, when run in VB6 work fine and allow AD users to be updated. When we include the code into an ASP Page and try and update a users information...
14
by: Arran Pearce | last post by:
Hi, I am looking for a way to use System.DirectoryServices to find all users on a domain whos accounts are either locked out or disabled. I have used ADSIEdit and the mmc schema add-in to try...
3
by: Roy Osherove | last post by:
Hi folks. I have an ASP.Net application that runs a .Net dll that uses WMI and ADSI(both managed) to connect to a given IIS root and search through it. When not using the ASP.Net client, but...
2
by: Dan Varozza | last post by:
I am trying to write a program in VB.NET to work with Active Directory user accounts in my Win2K domain. I found sample code as shown below but when I add it to a project it says "Type IADsContainer...
3
by: chat_devil | last post by:
hi, does anyone know if it is possible to remove an attribute that can not be read into the ADSI property cache/collection. i'm trying to do an eDirectory password change from .net directory...
1
by: LittlePython | last post by:
I am a little confused on why I can not detect an object that does not exist with a try and except. If I understand ADSI correctly from what I have read you do not create these objects but rather...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.