MAPI Logon fails (NT Service)

M

Michael Zino

Hi All,

I'm having problems with ex MAPI when its running from an NT service.

This is the code i'm running in the log on process.

Please... if you can see ANY problem, let me know....



void Logon(System::String* profile)

{

HRESULT hRes = -1;

LPVOID pMapiInit;

LPTSTR pprof;

FLAGS ntServiceMAPIField = MAPI_NT_SERVICE;

FLAGS mapiInitField = MAPI_NO_COINIT | MAPI_MULTITHREAD_NOTIFICATIONS;

FLAGS mapiLogonFlags = MAPI_NEW_SESSION | MAPI_NO_MAIL | MAPI_EXTENDED |
MAPI_EXPLICIT_PROFILE ;//| MAPI_PASSWORD_UI;

////////////////////////////////////////////////////////

// ***Important: Only if this module is a Service unmark the next 2 line.

mapiInitField |= ntServiceMAPIField;

mapiLogonFlags |= ntServiceMAPIField;

////////////////////////////////////////////////////////


MAPIINIT_0 MAPIINIT = { MAPI_INIT_VERSION, mapiInitField};

pMapiInit = &MAPIINIT;

if (FAILED(hRes = MAPIInitialize(pMapiInit)))

{

Marshal::ThrowExceptionForHR(hRes);

}

pprof = (char*)Marshal::StringToHGlobalAnsi(profile).ToPointer();

LPMAPISESSION __pin* pses = &m_pSes;

if (FAILED(hRes = MAPILogonEx((ULONG)0, pprof, NULL, mapiLogonFlags, pses)))

{

Marshal::FreeHGlobal(pprof);

Marshal::ThrowExceptionForHR(hRes);

}

m_pDefMsgStore = NULL;

Marshal::FreeHGlobal(pprof);

}





Regards,

Asaf
 
N

Nicholas Paldino [.NET/C# MVP]

Michael,

What account is the service running under? By default, I believe that
the account runs over the LOCALSYSTEM (or LOCALSERVICE, I can't remember the
name) account. This account doesn't have access to the netowkr, so you
would have to have the service run under an account which does have access
to the network.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top