Re: Remote call to COM impersonating another user
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Wed, 9 Jan 2008 00:14:34 +0100
"JCav" <jcavanaugh@xxxxxxxxxxxx> wrote in message news:4783da79$0$9628$4c368faf@xxxxxxxxxxxxxxxxx
These are the calls I'm using. LogonUser is failing with a 1326 - invalid userID or password, even though these work when I log onto the machine. So I never get far enough to make the call to the COM object.
int retxxx = CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, RpcAuthnLevel.Connect, RpcImpLevel.Impersonate, IntPtr.Zero, (int)EoAuthnCap.DynamicCloaking, IntPtr.Zero);
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_LOGON_NETWORK = 3;
IntPtr tokenHandle = new IntPtr(0);
bool returnValue = LogonUser(xxx", "yyy", "zzz",LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);
And you function declaration looks like:
[DllImport("advapi32", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr hToken);
bool result = LogonUser(name, domain, passwd,
LOGON32_LOGON_INTERACTIVE ,
LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if (result == false) // If failed
{
}
else // success
{
Note that you should use LOGON32_LOGON_INTERACTIVE or LOGON32_LOGON_BATCH (value 4) as logon type, other types will not return a token that can be used to impersonate unless you are running in the context of an administrator (or an account with "SeImpersonatePrivileges" enabled) .
Willy.
.
- Follow-Ups:
- References:
- Remote call to COM impersonating another user
- From: JCav
- Re: Remote call to COM impersonating another user
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Remote call to COM impersonating another user
- From: JCav
- Re: Remote call to COM impersonating another user
- From: Willy Denoyette [MVP]
- Re: Remote call to COM impersonating another user
- From: JCav
- Re: Remote call to COM impersonating another user
- From: Willy Denoyette [MVP]
- Re: Remote call to COM impersonating another user
- From: JCav
- Remote call to COM impersonating another user
- Prev by Date: Load New Record
- Next by Date: Re: Impersonate in 2.0 Winforms
- Previous by thread: Re: Remote call to COM impersonating another user
- Next by thread: Re: Remote call to COM impersonating another user
- Index(es):
Relevant Pages
|