开发者

Create a security identifier for the current domain

开发者 https://www.devze.com 2023-02-06 04:43 出处:网络
I want to create a security identifier for AccountDomainUsersSid. The problem is that I can\'t figure out how to get the sid for the current domain (i.e. the domain that开发者_高级运维 the current use

I want to create a security identifier for AccountDomainUsersSid. The problem is that I can't figure out how to get the sid for the current domain (i.e. the domain that开发者_高级运维 the current user is logged in to).

var sid = new SecurityIdentifier(WellKnownSidType.AccountDomainUsersSid, /* what do I write here? */);


SecurityIdentifier has an AccountDomainSid property.

The User property of the WindowsIdentity is a SecurityIdentifier.

WindowsIdentity has the GetCurrent() method that reutrns the current WindowsIdentity.

So this will write out the AccountDomainSid of the Current user

   WindowsIdentity id = WindowsIdentity.GetCurrent();
   Console.WriteLine(id.User.AccountDomainSid);
0

精彩评论

暂无评论...
验证码 换一张
取 消