当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryEntry.Close方法代码示例

本文整理汇总了C#中DirectoryEntry.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.Close方法的具体用法?C# DirectoryEntry.Close怎么用?C# DirectoryEntry.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DirectoryEntry的用法示例。


在下文中一共展示了DirectoryEntry.Close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main()
    {
        string path= "LDAP://DC=[DOMAIN],DC=local";
        string strAccountId = "[USERNAME]";
        string strPassword = "[PASSWORD]";
        bool bSucceeded;
        string strError;

        DirectoryEntry adsEntry = new DirectoryEntry(path, strAccountId, strPassword);

        DirectorySearcher adsSearcher = new DirectorySearcher( adsEntry );
        adsSearcher.Filter = "(sAMAccountName=" + strAccountId + ")";

        try
         {
          SearchResult adsSearchResult = adsSearcher.FindOne();
          bSucceeded = true;
          strError = "User has been authenticated by Active Directory.";
          adsEntry.Close();
         }
        catch ( Exception ex )
         {
            bSucceeded = false;
            strError = ex.Message;
            adsEntry.Close();
         }

         if (bSucceeded){
            Console.WriteLine("Great Success");
         }else {
            Console.WriteLine("Great Fail");
         }
    }
开发者ID:JeremyMorgan,项目名称:csharpworkshop,代码行数:33,代码来源:CommandLineAD.cs

示例2: Move

 // Summary:
 //     Performs and LDAP move on this Principal
 //
 // Returns:
 //     Void
 //
 // Exceptions:
 //
 public void Move(string ldapPath, string newName)
 {
     /* This whole method is needed because AccountManagement does not provide a Principal.Move() method.
      * So we have to peel back layers of the onion and do it ourselves.
      */
     //For brevity, removed existence checks
     var eLocation = new DirectoryEntry("LDAP://" + DistinguishedName);
     var nLocation = new DirectoryEntry("LDAP://" + ldapPath);
     if (string.IsNullOrEmpty(newName))
     {
         newName = eLocation.Name;
     }
     eLocation.MoveTo(nLocation, newName);
     nLocation.Close();
     eLocation.Close();
 }
开发者ID:blinds52,项目名称:ActiveDirectoryServices,代码行数:24,代码来源:ComputerPrincipalFull.cs

示例3: RemoveMember

 // Summary:
 //     Removes the distinguished name of the supplied Principal object from the member attribute belonging to this GroupPrincipalFull
 //
 // Returns:
 //     void
 //
 // Exceptions:
 //
 public void RemoveMember(Principal principal)
 {
     var groupDe = new DirectoryEntry(string.Format("LDAP://{0}", DistinguishedName));
     groupDe.Properties["member"].Remove(principal.DistinguishedName);
     groupDe.CommitChanges();
     groupDe.Close();
 }
开发者ID:blinds52,项目名称:ActiveDirectoryServices,代码行数:15,代码来源:GroupPrincipalFull.cs

示例4: RemoveAllMembers

 // Summary:
 //     Removes all members belonging to this GroupPrincipalFull
 //
 // Returns:
 //     void
 //
 // Exceptions:
 //
 public void RemoveAllMembers()
 {
     var groupDe = new DirectoryEntry(string.Format("LDAP://{0}", DistinguishedName));
     groupDe.Properties["member"].Clear();
     groupDe.CommitChanges();
     groupDe.Close();
 }
开发者ID:blinds52,项目名称:ActiveDirectoryServices,代码行数:15,代码来源:GroupPrincipalFull.cs

示例5: LookForUserInAllDomains

    public static DataTable LookForUserInAllDomains(string sLastNameSearch, string sFirstNameSearch)
    {
        if (sUID == "") sUID = null;
        if (sPwd == "") sPwd = null;

        CreateNetworkUserTable();
        objTable.Rows.Clear();

        ////Search in all the domains
        //string ldapdomains = System.Configuration.ConfigurationManager.AppSettings["LDAPDomains"].ToString();
        //string[] Domains = ldapdomains.Split(new char[] { ';' });

        //for (int i = 0; i < Domains.Length; i++)
        //{
        //    string domainName = Domains[i];

        //    objTable = LookForUserInDomain(domainName, sLastNameSearch, sFirstNameSearch);

        //}

        string sFilter = String.Format("(|(&(objectClass=User)(givenname={0})(sn={1})))", sFirstNameSearch, sLastNameSearch);

        // collect inactive users in all the domains
        string[] sDomains = sLDAPDomains.Split(new char[] { ';' });
        for (int i = 0; i < sDomains.Length; i++ )
        {
            string sDomainName = sDomains[ i ];
            string sServerName = System.Configuration.ConfigurationManager.AppSettings[sDomainName].ToString();
            string sLDAPPath = "LDAP://" + sServerName + "/DC=" + sDomainName + ",DC=root01,DC=org";

            DirectoryEntry objRootDE = new DirectoryEntry(sLDAPPath, sUID, sPwd, AuthenticationTypes.Secure);
            DirectorySearcher objDS = new DirectorySearcher(objRootDE);

            objDS.Filter = sFilter;
            objDS.ReferralChasing = ReferralChasingOption.None;
            objDS.PropertiesToLoad.Add("userAccountControl");
            objDS.PropertiesToLoad.Add("SAMAccountName");
            objDS.PropertiesToLoad.Add("givenName");
            objDS.PropertiesToLoad.Add("sn");
            objDS.PropertiesToLoad.Add("TelephoneNumber");
            objDS.PropertiesToLoad.Add("mail");

            SearchResultCollection objSRC = null;
            try
            {
                objSRC = objDS.FindAll();
            }
            catch (Exception excpt)
            {
                if (excpt.Message.IndexOf("The server is not operational.") < 0)
                    throw;
            }

            if (objSRC == null)
                continue;

            foreach (SearchResult objSR in objSRC)
            {
                int iInactiveFlag	= Convert.ToInt32(objSR.Properties["userAccountControl"][0]);
                string sUserId		= objSR.Properties["SAMAccountName"][0].ToString();
                string sFirstName	= objSR.Properties["givenName"][0].ToString();
                string sLastName	= objSR.Properties["sn"][0].ToString();

                string sPhone	= "";
                string sEmail	= "";

                if (objSR.Properties["TelephoneNumber"].Count > 0)
                    sPhone	= objSR.Properties["TelephoneNumber"][0].ToString();

                if( objSR.Properties["mail"].Count > 0 )
                    sEmail	= objSR.Properties["mail"][0].ToString();

                iInactiveFlag = iInactiveFlag & 0x0002;
                if (iInactiveFlag <= 0)
                {
                    // add name, username, phone and email to the table, if active
                    DataRow objRow = objTable.NewRow();

                    objRow["LastName"] = sLastName;
                    objRow["FirstName"] = sFirstName;
                    objRow["Username"] = sUserId;
                    objRow["UserDomain"] = sDomainName;
                    objRow["Phone"] = sPhone;
                    objRow["Email"] = sEmail;

                    objTable.Rows.Add( objRow );

                    continue;
                }
            }

            objSRC.Dispose();
            objDS.Dispose();
            objRootDE.Close();
            objRootDE.Dispose();
        }

        return objTable;
    }
开发者ID:fmendes,项目名称:ActiveDirectory,代码行数:99,代码来源:NetworkUsersMapping.cs

示例6: RetrieveAllNetworkUsersFromLDAP

    private static SearchResultCollection RetrieveAllNetworkUsersFromLDAP(string sDomainName)
    {
        string sServerName = System.Configuration.ConfigurationManager.AppSettings[sDomainName].ToString();
        string sLDAPPath = "LDAP://" + sServerName + "/DC=" + sDomainName + ",DC=root01,DC=org";

        DirectoryEntry objRootDE = new DirectoryEntry(sLDAPPath, sUID, sPwd, AuthenticationTypes.Secure);
        DirectorySearcher objDS = new DirectorySearcher(objRootDE);

        objDS.Filter = "(|(&(objectClass=User)(givenname=*)(sn=*)))";
        objDS.ReferralChasing = ReferralChasingOption.None;
        objDS.PropertiesToLoad.Add("userAccountControl");
        objDS.PropertiesToLoad.Add("SAMAccountName");

        SearchResultCollection objSRC = null;
        try
        {
            objSRC = objDS.FindAll();
        }
        catch (Exception excpt)
        {
            if (excpt.Message.IndexOf("The server is not operational.") < 0)
                throw;
        }

        objDS.Dispose();
        objRootDE.Close();
        objRootDE.Dispose();
        return objSRC;
    }
开发者ID:fmendes,项目名称:ActiveDirectory,代码行数:29,代码来源:NetworkUsersMapping.cs


注:本文中的DirectoryEntry.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。