Create a security identifier for the current domain
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);
精彩评论