计算机用户有什么不同,c# – 有什么方法可以区分“人员用户帐户”和“计算机用户帐户”吗?...

如果您使用的是.NET 3.5及更高版本,则应该查看System.DirectoryServices.AccountManagement(S.DS.AM)命名空间.在这里阅读所有相关内容:

基本上,您可以定义域上下文并轻松查找AD中的用户和/或组:

// set up domain context

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user

UserPrincipal user = UserPrincipal.FindByIdentity(ctx,"SomeUserName");

if(user != null)

{

// do something here....

}

// find the group in question

GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx,"YourGroupNameHere");

// if found....

if (group != null)

{

// iterate over members

foreach (Principal p in group.GetMembers())

{

Console.WriteLine("{0}: {1}",p.StructuralObjectClass,p.DisplayName);

// do whatever you need to do to those members

}

}

新的S.DS.AM使得在AD中使用用户和群组变得非常容易:

计算机帐户将显示为ComputerPrincipal(源自Principal) – 因此您可以轻松地将用户和计算机帐户分开.

如果您不能或不想转移到S.DS.AM – 您还可以通过在LDAP过滤器中使用objectCategory而不是objectClass来保持用户和计算机的区别. objectCategory无论如何都是有益的,因为它是索引的,而不是多值的 – 所以查询性能会好得多.

对于真实用户,请使用objectCategory = Person,而对于计算机,请在LDAP过滤器中使用objectCategory = Computer.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值