Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? */);
like image 649
jgauffin Avatar asked Dec 16 '22 18:12

jgauffin


1 Answers

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);
like image 63
Conrad Frix Avatar answered Dec 28 '22 11:12

Conrad Frix