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

Last reviewed: February 6, 1998
Article ID: Q180597
The information in this article applies to:
  • Extended Messaging Application Programming Interface (MAPI), version 1.0

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 : EMAPI
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.