I am trying to get the WindowsIdentity for the computer account the current user is logged into.
Currently I am using the following code to get the group membership of the current user:
WindowsIdentity currentIdent = WindowsIdentity.GetCurrent();
foreach (IdentityReference indentity in currentGroups)
{
String groupName = indentity.Translate(typeof(NTAccount)).ToString();
}
This works fine, but I also need to do the same for the current computer account preferably without querying AD.
I beleive that I will have to do this using Impersonation but have not been able to find out how.
There are two places on the local computer that would have its domain account group membership: a user token for domain\computer$ and a Kerberos ticket for domain\computer$. Whenever the local computer needs its user token, then it will be set up as SYSTEM, not domain\computer$, so that's not an option. The only way to get a user token from a domain\computer$ Kerberos ticket is to be running as SYSTEM, since you need its key to decrypt the ticket (also, you would need the Act as Part of the Operating System privilege, and even then I don't know how to create the token from the ticket).
So, you have to query AD: