/// <summary> /// Obtain user from Windows Active Directory using simple Username format /// </summary> /// <remarks> /// Reserved for simple network which have single domain and logon username in simple format /// </remarks> /// <history> /// [tamttt] 08/01/2004 Created /// </history> public static DirectoryEntry GetUser0(string Name) { // Create search object then assign required params to get user entry in Active Directory Search objSearch = new Search(GetRootDomain()); DirectoryEntry userEntry; objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.person.ToString()); objSearch.AddFilter(Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, Name); userEntry = objSearch.GetEntry(); return(userEntry); }
/// <summary> /// Obtain user from Windows Active Directory using UPN format - USERNAME@DOMAIN /// </summary> /// <remarks> /// </remarks> /// <history> /// [tamttt] 08/01/2004 Created /// </history> public static DirectoryEntry GetUserByUPN0(string Name, Domain RootDomain) { // Create search object then assign required params to get user entry in Active Directory Search objSearch = new Search(RootDomain); DirectoryEntry userEntry; // UPN is unique in entire Windows network objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.person.ToString()); objSearch.AddFilter(Configuration.ADSI_UPN, CompareOperator.Is, Name); userEntry = objSearch.GetEntry(); return(userEntry); }
private void PopulateChild(Domain Domain) { Search objSearch = new Search(Domain); objSearch.SearchScope = SearchScope.OneLevel; objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ToString().ToString()); ArrayList resDomains = objSearch.GetEntries(); DirectoryEntry entry; foreach (DirectoryEntry tempLoopVar_entry in resDomains) { entry = tempLoopVar_entry; Domain child; //If (Not Domain.Username Is Nothing) AndAlso (Not Domain.Password Is Nothing) Then // child = ADSI.Domain.GetDomain(entry.Path, Domain.Username, Domain.Password, Domain.AuthenticationType) //Else child = GetDomain(entry.Path); //End If if (child != null) { child.ParentDomain = Domain; child.Level = Domain.Level + 1; // Add this child into childDomains collection Domain.ChildDomains.Add(child); // add this child and all it's child into allchilddomains collection Domain.AllChildDomains.Add(child); Domain.AllChildDomains.AddRange(child.AllChildDomains); } } }
private void PopulateChild( Domain Domain ) { Search objSearch = new Search( Domain ); objSearch.SearchScope = SearchScope.OneLevel; objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ToString().ToString() ); ArrayList resDomains = objSearch.GetEntries(); DirectoryEntry entry; foreach( DirectoryEntry tempLoopVar_entry in resDomains ) { entry = tempLoopVar_entry; Domain child; //If (Not Domain.Username Is Nothing) AndAlso (Not Domain.Password Is Nothing) Then // child = ADSI.Domain.GetDomain(entry.Path, Domain.Username, Domain.Password, Domain.AuthenticationType) //Else child = GetDomain( entry.Path ); //End If if( child != null ) { child.ParentDomain = Domain; child.Level = Domain.Level + 1; // Add this child into childDomains collection Domain.ChildDomains.Add( child ); // add this child and all it's child into allchilddomains collection Domain.AllChildDomains.Add( child ); Domain.AllChildDomains.AddRange( child.AllChildDomains ); } } }
public static DirectoryEntry GetGroupEntryByName(string GroupName) { Domain RootDomain = GetRootDomain(); Search objSearch = new Search(RootDomain); objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.group.ToString()); objSearch.AddFilter(Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, GroupName); DirectoryEntry groupEntry = objSearch.GetEntry(); if (groupEntry != null) { return(groupEntry); } else { return(null); } }
/// <summary> /// </summary> /// <remarks> /// in multiple domains network that search result return more than one group with the same name (i.e Administrators) /// </remarks> /// <history> /// [tamttt] 08/01/2004 Created /// </history> public static ArrayList GetGroupEntriesByName(string GroupName) { Domain RootDomain = GetRootDomain(); Search objSearch = new Search(RootDomain); objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.group.ToString()); objSearch.AddFilter(Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, GroupName); ArrayList groupEntries = objSearch.GetEntries(); if (groupEntries != null) { return(groupEntries); } else { return(null); } }
/// <summary> /// Obtain user from Windows Active Directory using LogonName format - NETBIOSNAME\USERNAME /// </summary> /// <remarks> /// -In multiple domains network, search result might return more than one user with the same name /// -Additional steps to check by domain name to get correct user /// </remarks> public static DirectoryEntry GetUserEntryByName(string Name) { Search objSearch = new Search(GetRootDomain()); objSearch.AddFilter("objectClass", CompareOperator.Is, ObjectClass.person.ToString()); objSearch.AddFilter("sAMAccountName", CompareOperator.Is, TrimUserDomainName(Name)); ArrayList userEntries = objSearch.GetEntries(); switch (userEntries.Count) { case 0: { return(null); } case 1: { return((DirectoryEntry)userEntries[0]); } } Domain userDomain = GetDomainByBIOSName(GetUserDomainName(Name)); if (userDomain == null) { return((DirectoryEntry)userEntries[0]); } foreach (DirectoryEntry userEntry in userEntries) { string entryPath = userEntry.Path; string entryLocation = entryPath.Substring(entryPath.Length - entryPath.Length - entryPath.IndexOf("DC="), entryPath.Length - entryPath.IndexOf("DC=")); if (entryLocation.ToLower() == userDomain.DistinguishedName.ToLower()) { return(userEntry); } } objSearch = null; return(null); }
/// <summary> /// Obtain user from Windows Active Directory using LogonName format - NETBIOSNAME\USERNAME /// </summary> /// <remarks> /// -In multiple domains network, search result might return more than one user with the same name /// -Additional steps to check by domain name to get correct user /// </remarks> public static DirectoryEntry GetUserEntryByName( string Name ) { Search objSearch = new Search( GetRootDomain() ); objSearch.AddFilter( "objectClass", CompareOperator.Is, ObjectClass.person.ToString() ); objSearch.AddFilter( "sAMAccountName", CompareOperator.Is, TrimUserDomainName( Name ) ); ArrayList userEntries = objSearch.GetEntries(); switch( userEntries.Count ) { case 0: { return null; } case 1: { return ( (DirectoryEntry)userEntries[0] ); } } Domain userDomain = GetDomainByBIOSName( GetUserDomainName( Name ) ); if( userDomain == null ) { return ( (DirectoryEntry)userEntries[0] ); } foreach( DirectoryEntry userEntry in userEntries ) { string entryPath = userEntry.Path; string entryLocation = entryPath.Substring( entryPath.Length - entryPath.Length - entryPath.IndexOf( "DC=" ), entryPath.Length - entryPath.IndexOf( "DC=" ) ); if( entryLocation.ToLower() == userDomain.DistinguishedName.ToLower() ) { return userEntry; } } objSearch = null; return null; }
/// <summary> /// Obtain user from Windows Active Directory using UPN format - USERNAME@DOMAIN /// </summary> /// <remarks> /// </remarks> /// <history> /// [tamttt] 08/01/2004 Created /// </history> public static DirectoryEntry GetUserByUPN0( string Name, Domain RootDomain ) { // Create search object then assign required params to get user entry in Active Directory Search objSearch = new Search( RootDomain ); DirectoryEntry userEntry; // UPN is unique in entire Windows network objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.person.ToString() ); objSearch.AddFilter( Configuration.ADSI_UPN, CompareOperator.Is, Name ); userEntry = objSearch.GetEntry(); return userEntry; }
/// <summary> /// Obtain user from Windows Active Directory using simple Username format /// </summary> /// <remarks> /// Reserved for simple network which have single domain and logon username in simple format /// </remarks> /// <history> /// [tamttt] 08/01/2004 Created /// </history> public static DirectoryEntry GetUser0( string Name ) { // Create search object then assign required params to get user entry in Active Directory Search objSearch = new Search( GetRootDomain() ); DirectoryEntry userEntry; objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.person.ToString() ); objSearch.AddFilter( Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, Name ); userEntry = objSearch.GetEntry(); return userEntry; }
public static DirectoryEntry GetGroupEntryByName( string GroupName ) { Domain RootDomain = GetRootDomain(); Search objSearch = new Search( RootDomain ); objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.group.ToString() ); objSearch.AddFilter( Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, GroupName ); DirectoryEntry groupEntry = objSearch.GetEntry(); if( groupEntry != null ) { return groupEntry; } else { return null; } }
/// <summary> /// </summary> /// <remarks> /// in multiple domains network that search result return more than one group with the same name (i.e Administrators) /// </remarks> /// <history> /// [tamttt] 08/01/2004 Created /// </history> public static ArrayList GetGroupEntriesByName( string GroupName ) { Domain RootDomain = GetRootDomain(); Search objSearch = new Search( RootDomain ); objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.group.ToString() ); objSearch.AddFilter( Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, GroupName ); ArrayList groupEntries = objSearch.GetEntries(); if( groupEntries != null ) { return groupEntries; } else { return null; } }