How to impersonate WellKnownSidType?

I know I can impersonate a Windows account using: http://msdn.microsoft.com/en-us/library/chf6fbt4.aspx

But how do I get myself to issue an account WellKnownSidType

?

SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
NTAccount account = sid.Translate(typeof(NTAccount)) as NTAccount;
if (account != null)
{
    //Impersonate here???
}

      

+1


source to share


2 answers


First, you will not be able to impersonate built-in accounts such as "Network Service" or "Local Service" unless you are running under the "Local Service" account, which to my knowledge can only be executed by the OS.

The following post provides a possible solution to the above (I haven't tried it, just searched for it before I started writing it all myself), but it looks reasonable.

http://geek.hubkey.com/2008/02/impersonating-built-in-service-account.html



Once started under the Local Service account, you just need to use the LogonUser (also shown in the link above) to log in using the account name of the well known SID and then issue the token.

I see the link above, runs "CMD.EXE" as a service that can be allowed to interact with the desktop, please note that the "interact with desktop" functionality has been deprecated.

+2


source


Use the WindowsIdentity constructor and follow the directions here . Among other things, you will need to "act as part of the operating system".



0


source







All Articles