HOWTO: Get the Name of the Profile you Logged On With

ID: Q180597

The information in this article applies to:

SUMMARY

This article describes the process of programmatically determining what profile was used to log on to the current session.

MORE INFORMATION

To find out which profile was used to start the current session, follow these steps:

1. Call IMAPISession::GetStatusTable() to retrieve a table with information

   about all of the MAPI resources in the session. This table contains
   information about the session including the current profile name. The
   following steps outline how to get the profile name out of the table.

2. Call IMAPITable::SetColumns() to reduce the table to only the
   PR_DISPLAY_NAME and PR_RESOURCE_TYPE columns.

3. Next, set up a restriction to find the entry in the table where
   PR_RESOURCE_TYPE equals MAPI_SUBSYSTEM. Use IMAPITable::Restrict() to
   apply this restriction to the table.

4. Call IMAPITable::QueryRows() to retrieve the row in the table that
   contains the information about the current profile.

5. The row returned from QueryRows() contains the name of the current
   profile.

Here is a code sample that demonstrates the process above:

   // Note: Mapi32.lib is required to successfully compile and link
   // the following code.
   #include <mapix.h>
   #include <mapiutil.h>
   #include <stdio.h>

   HRESULT         hr = S_OK;
   LPMAPISESSION   lpSession = NULL;
   LPMAPITABLE     lpStatusTable = NULL;

   SRestriction    sres;
   SPropValue      spvResType;
   LPSRowSet       pRows = NULL;
   LPTSTR          lpszProfileName = NULL;

   SizedSPropTagArray(2, Columns) =
   {
      2, PR_DISPLAY_NAME, PR_RESOURCE_TYPE
   };

   hr = MAPIInitialize(NULL);

   // Log on to the Extended MAPI session.
   hr = MAPILogonEx((ULONG)GetActiveWindow(),
            NULL,
            NULL,
            MAPI_LOGON_UI | MAPI_NEW_SESSION,
            &lpSession);
   hr = lpSession->GetStatusTable(NULL, &lpStatusTable);
   hr = lpStatusTable->SetColumns((LPSPropTagArray)&Columns, NULL);

   spvResType.ulPropTag = PR_RESOURCE_TYPE;
   spvResType.Value.ul = MAPI_SUBSYSTEM;

   sres.rt = RES_PROPERTY;
   sres.res.resProperty.relop = RELOP_EQ;
   sres.res.resProperty.ulPropTag = PR_RESOURCE_TYPE;
   sres.res.resProperty.lpProp = &spvResType;

   hr = lpStatusTable->Restrict(&sres, TBL_ASYNC);

   hr = lpStatusTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);

   // We have a match.
   hr = lpStatusTable->QueryRows(1,0,&pRows);

   if (SUCCEEDED(hr))
   {
      lpszProfileName = pRows->aRow[0].lpProps[0].Value.lpszA;
      printf("You logged onto profile \"%s\"\n", lpszProfileName);
   }

Additional query words: Default Profile MAPILogonEx Session StatusTable
Keywords          : kbMsg kbMAPI100 
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: February 8, 1998