[ACCEPTED]-Using advapi32.dll:LogonUserA() to impersonate a remote machine's local user-remote-access

Accepted answer
Score: 12

Here's what I have been using without having 3 to define a local user:

const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
const int LOGON32_PROVIDER_DEFAULT = 0;

bool isSuccess = LogonUser(username, domain, password,
            LOGON32_LOGON_NEW_CREDENTIALS,
            LOGON32_PROVIDER_DEFAULT, ref token);

After that:

WindowsIdentity newIdentity = new WindowsIdentity(token);
WindowsImpersonationContext impersonatedUser = newIdentity.Impersonate();

I don't 2 duplicate the handle though.

Another observation 1 - I don't use LogonUserA, I simply use LogonUser.

More Related questions