Re: Remote call to COM impersonating another user

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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.



.



Relevant Pages

  • Impersonation?
    ... string lpszUsername, ... int dwLogonType, ... IntPtr tokenHandle = new IntPtr; ... bool returnValue = LogonUser(userName, domainName, password, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • VSTO 2005 COM Add-In Word Buttons not responding after first click
    ... connectMode, object addInInst, ref System.Array custom) ... DME.SearchResults objSearchResults; ... string sDocumentID = null; ... sDocumentID = oForm.txtDocID.Text; ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: How to convert Infix notation to postfix notation
    ... I will assume that that string is not the ONLY string you have to ... In turn an additionFactor can be just a ... parenthesis, but the one that actually balances the left parenthesis. ... return expression(strInstring, ref intIndex1, ref strPolish);} ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... Briefly it failed for a null string and a blank. ... letter without checking intIndex for being out of bounds. ... ref strPolish, ... ref strErrorMessage, ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... I will assume that that string is not the ONLY string you have to ... parenthesis, but the one that actually balances the left parenthesis. ... return expression(strInstring, ref intIndex1, ref strPolish); ...
    (comp.lang.c)