![](/img/trans.png)
[英]How do I find a user's Active Directory display name in a C# web application?
[英]How do I find a user and the security group they belong to in active directory with their username and password in C#?
我正在尝试使用用户名和密码将用户从Active Directory中删除。 除了获取他们所属的安全组之外,还有人知道如何在C#中执行此操作吗?
编辑:这个问题变得更加复杂(会议后要求对我有所改变)。 安全组嵌套在AD中。
查看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()
在这里看看: 查找活动目录中特定用户所属的组/分发列表 。 要点与tokenGroups
属性有关。 顺便说一句,您不需要用户密码,只需输入用户名即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.