代码之家  ›  专栏  ›  技术社区  ›  Korbin

如何在Active Directory中查找用户名和密码为c_的用户及其所属的安全组?

  •  0
  • Korbin  · 技术社区  · 15 年前

    我正在尝试使用用户的用户名和密码将其从Active Directory中删除。除了获得他们所属的安全组之外,还有人知道如何在C中执行此操作吗?

    编辑:这个问题变得更复杂了(在一次会议后我的要求发生了变化)。安全组嵌套在AD中。

    3 回复  |  直到 15 年前
        1
  •  0
  •   Community CDub    8 年前

    请看这里: Finding what Groups/Distribution lists a specific user belongs to in active directory . 要点与 tokenGroups 财产。顺便说一句,你不需要使用用户密码,只需要用户名。

        2
  •  0
  •   Rubens Farias    15 年前

    查看DirectoryEntry类。

    这里有一个样本:

    Dim dirEntry As DirectoryEntry
    dirEntry = New DirectoryEntry("your LDAP info", "administrator", "password")
    
    Dim entries As DirectoryEntries = dirEntry.Children
    '' // Set login name and full name. 
    Dim newUser As DirectoryEntry = entries.Add("CN=JONNY BOY", "User")
    
    newUser.Properties("sAMAccountName").Add("jboy")
    newUser.CommitChanges()
    newUser.Invoke("SetPassword", "hi2343145gfdtgwdt")
    Dim flags As Integer
    
    flags = CInt(newUser.Properties("userAccountControl").Value)
    
    '' //enable user below
    newUser.Properties("userAccountControl").Value = flags And Not &H2
    
    '' //disable user below
    newUser.Properties("userAccountControl").Value = flags Or &H1
    
    
    '' //lockout property
    Dim l As Long
    l = CType(newUser.Properties("lockoutTime").Value, Long)
    
    If l <> 0 Then
        '' //account is locked out
    
        '' //so how do we unlock it?
        '' //we unlock it by setting it to 0
        newUser.Properties("lockoutTime").Value = 0
    Else
        '' //account is 0 it is NOT locked out
    
    End If
    
    newUser.CommitChanges()
    
    Dim j As DirectoryEntry = entries.Find("CN=JONNY BOY", "User")
    j.Properties("mail").Value = "jon@yahoo.com"
    j.CommitChanges()
    
        3
  •  0
  •   Korbin    15 年前

    我终于找到了解决这个问题的办法。这篇文章的代码很有魅力。 Nested AD Groups