How do I initialize MAPI Properly for a Console Application which runs from Scheduled Task.



Hi,

I found a MS KB article that show how to run a MAPI program as a service.
However, my program is not a service it is simply a "console application" I
wish to schedule the program using Windows scheduled tasks and it will run
once per day.

Can someone look over the flags I have set? I don't know if I have these
right.

I will be setting a Username and Password in the task so this means I
shouldn't need any impersonation. So when the Console application gets
executed by windows it should use the Username and Password I entered when I
configured the task right?

Thanks
Russell Mangel

// Begin code

HRESULT hr = NULL;
ULONG ulFlags = 0;

MAPIINIT_0 pMapiInit = { MAPI_INIT_VERSION, MAPI_NT_SERVICE };
hr = MAPIInitialize(&pMapiInit);
if(FAILED(hr)){printf("MAPIInitialize failed\n");goto CleanUp;}

ulFlags =
MAPI_NO_MAIL|MAPI_NEW_SESSION|MAPI_EXPLICIT_PROFILE|MAPI_NT_SERVICE ;
LPMAPISESSION lpSession = NULL;
hr = MAPILogonEx(0,lpszProfileName,NULL,ulFlags,&lpSession);
if(FAILED(hr)){printf("MAPILogonEx failed.\n");goto CleanUp;}


.



Relevant Pages


Loading