SIDがユーザーまたはグループであるかどうかを確認します

StackOverflow https://stackoverflow.com//questions/9653500

  •  11-12-2019
  •  | 
  •  

質問

指定されたSIDが.NETを使用しているユーザーまたはグループであるかどうかを判断することができますか? ListViewで編集する必要があるSIDのリストがありますので、ユーザーとグループのためにさまざまなアイコンを使用したいのです。

役に立ちましたか?

解決

System.DirectoryServices.accountmanagement:を使用して試すことができます。

//Get NTAccount, to find out username and domen
NTAccount nt = (NTAccount)sid.Translate(typeof(NTAccount));
string[] fullName = nt.Value.Split(new char[] { '\\' });

//then get group principle
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, fullName[0]);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, fullName[1]);

//and check whenever this group exists
bool SidIsAGroup = grp != null;
.

ここで似た質問を見つけることができます。-directory-c-asp-net "> Active Directoryでユーザーのグループを取得する方法は?(C#、ASP.NET)

他のヒント

LookupAccountSid()関数は、アカウントの種類を示すsid_name_use値を返します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top