Check if AD User Exists

cjwallace

Member
Joined
May 5, 2007
Messages
13
Programming Experience
Beginner
Hi Guys.

I have a project that i am working on and have been picking up and putting down for sometime. The project is a user creation script that i am trying to convert over from vbscript.

Anyway i have been looking around trying to find away to search active directory to see if my user accounts exists before i create it.

If it finds the account or if it is ok to use display a msgbox

can anyone help i am a bit stuck

Thanks in advance
 
Hi guys.

I have found this bit of code that will do what i want it to do.....i think

public Boolean UserExists(string funuser)

SearchResultCollection results = null;
string strpath = LDAP://RootDSE;
DirectoryEntry de = new DirectoryEntry(strpath);
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot = de;
searcher.Filter = "(SAMAccountName=" + funuser +")";
results= searcher.FindAll();
if(results.Count == 0)return false;
return true;

can someone please help me to get it to work under vb.net 2005?

The code is .net but causes more errors than i care to list here.

Thanks in advance
 
It probably causes errors because you need to add the references to LDAP and active directory for it to work.

Google for "active directory VB.net user authentication" and that should show you what you require - the code above should then (in theory) work
 
Back
Top