Noe*_*edy 2 .net c# ldap active-directory
这应该是非常容易的,但由于某些原因,它似乎不是.我想询问AD当前机器是否是特定组的成员.直接会员资格很好.
集团仅包含8台PC,极不可能超过30台.
C#代码示例赞赏!
这是使用System.DirectoryServices命名空间的示例方法:
public bool BelongsToGroup(string computerName, string groupName, string domain)
{
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, domain);
ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(domainContext, computerName);
foreach (Principal result in computer.GetGroups())
{
if (result.Name == groupName)
{
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
所以你可以这样称呼它:
string computerName = Environment.MachineName;
string groupName = "Group Name";
string domainName = "Domain Name";
bool test = BelongsToGroup(computerName, groupName, domainName);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2293 次 |
| 最近记录: |