SetSearchPath? Not Really


This is a follow up to our documentation on PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY. There, we discussed how Outlook 2010 has a property which can override the container specified in SetDefaultDir. Today, we’re going to override SetSearchPath. Let’s look at our dialog again:

Address Book Tools Options Dialog

That list of address books under Custom is what we set using SetSearchPath. How can we set “Start with Global Address List” or “Start with contact folders”? There’s a prop for that: PR_AB_SEARCH_PATH_CUSTOMIZATION, which you’ll find in the same place as PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY, on the profile section IID_CAPONE_PROF.

Here’s the property definition:

#define PR_AB_SEARCH_PATH_CUSTOMIZATION( PT_LONG, 0x3D1B)

Here are the valid settings:

typedef enum _SearchPathReorderType
{
                SEARCHPATHREORDERTYPE_RAW = 0,
                SEARCHPATHREORDERTYPE_ACCT_PREFERGAL,
                SEARCHPATHREORDERTYPE_ACCT_PREFERCONTACTS,
} SearchPathReorderType;

Finally, here’s a description of each of the settings:

  • SEARCHPATHREORDERTYPE_RAW:

    Return a list of the containers that are in the persisted MAPI search path. This is the "Custom" search path option in the UI.
  • SEARCHPATHREORDERTYPE_ACCT_PREFERGAL:

    Group the search path based on the mail accounts in the profile, prefer the given sending account, and within each account, prefer the GAL. An example reordering here sending from account B would be the following:

    Persisted search Path:

    Contacts A

    GAL A

    GAL B

    GAL C

    Contacts D

    Contacts D2

    Contacts C

    Contacts B

    Reordered Search Path sending from B with this option:

    GAL B

    Contacts B

    GAL A

    Contacts A

    GAL C

    Contacts C

    Contacts D

    Contacts D2

  • SEARCHPATHREORDERTYPE_ACCT_PREFERCONTACTS

    Group the search path based on the mail accounts in the profile, prefer the given sending account, and within each account, prefer that account’s contacts folders. An example reordering here sending from account B would be the following:

    Persisted search Path:

    Contacts A

    GAL A

    GAL B

    GAL C

    Contacts D

    Contacts D2

    Contacts C

    Contacts B

    Reordered Search Path sending from B with this option:

    Contacts B

    GAL B

    Contacts A

    GAL A

    Contacts C

    GAL C

    Contacts D

    Contacts D2

Enjoy!

Comments (8)

  1. Yair Glikman says:

    here is the code…

    DEFINE_OLEGUID(IID_CAPONE_PROF, 0x00020d0a, 0, 0);

    #define PR_AB_SEARCH_PATH_CUSTOMIZATION PROP_TAG( PT_LONG, 0x3D1B)

    #define PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY PROP_TAG( PT_BOOLEAN, 0x3D1C)

    int SetCustominzation(IMAPISession &lpSession) {

      HRESULT hr;

      LPPROFSECT lpProfileSection = NULL;

      LPSPropValue lpPropValue = NULL;

      LONG FAR * ulPropCnt = NULL;

      LPSPropValue FAR * pProps = NULL;

      hr = lpSession.OpenProfileSection((LPMAPIUID)&IID_CAPONE_PROF, NULL, MAPI_MODIFY  , &lpProfileSection);

    if (hr == S_OK) {

    //if (SUCCEEDED ( hr = HrGetOneProp(lpProfileSection, PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY, &lpPropValue))) good for select auto

    if (SUCCEEDED ( hr = HrGetOneProp(lpProfileSection, PR_AB_SEARCH_PATH_CUSTOMIZATION, &lpPropValue)))

    {

    //printf("Server DN: %dn", lpPropValue->Value.b); for good select auto

    lpPropValue->Value.l = 0;

    if (SUCCEEDED(hr = HrSetOneProp(lpProfileSection, lpPropValue)))

    return S_OK; // good

    else

    return 3;

    MAPIFreeBuffer(lpPropValue);  

    }    

    else

    return 2; // cant get the prop

    lpProfileSection->Release();

    }

    else

    return 1; // cant connect to IID_CAPONE_PROF

    }

    yair.glikman@rtc-vision.com

  2. Jean says:

    First of all, sorry for my English.

    I try to set the profile configuration.

    I found how to set the Resolution Order for Address Lists, but I need now to set

    PR_AB_SEARCH_PATH_CUSTOMIZATION to "Custom".

    I use Visual C++ 2008 Express

    I have an error "error C2440: 'cast de type' : impossible de convertir de 'const GUID' en 'LPMAPIUID'"

    on the line

    if (FAILED ( hRes = lpSession->OpenProfileSection((LPMAPIUID)IID_CAPONE_PROF, NULL, MAPI_MODIFY, &lpProfSect)))

    I normaly work with C# and I don't understand what I miss here.

    Thanks

    Jean

    {

  3. Stephen Griffin says:

    You left out the &:

    if (FAILED ( hRes = lpSession->OpenProfileSection((LPMAPIUID)&IID_CAPONE_PROF, NULL, MAPI_MODIFY, &lpProfSect)))

  4. Jean says:

    Hello, and thanks for your answer.

    I get this error when I try with the syntax with "&IID_CAPONE_PROF"

    ——–

    1>ChangeAddressBookListOrder32.obj : error LNK2001: symbole externe non résolu _IID_CAPONE_PROF

    1>C:ChangeAddressBookListOrder32DebugChangeAddressBookListOrder32.exe : fatal error LNK1120: 1 externes non résolus

    ———

    have you an idea ?

    Thanks

    Jean

  5. Stephen Griffin says:

    That's discussed here: support.microsoft.com/…/130869

  6. Jean says:

    Hello,

    I have another question.

    The code works well when user has at least selects one time the radio button "Custom". But if it's a new profile, the is an error on "HrGetOneProp(lpProfSect,PR_AB_SEARCH_PATH_CUSTOMIZATION, &lpPropValue)".

    How can I initialise this property the first time ?

    Thanks

    Jean

  7. Jean says:

    I found the solution for my last question.

    Here the code if someone have the same problem.

    Thanks

    Jean

    if (FAILED ( hRes = HrGetOneProp(lpProfSect,PR_AB_SEARCH_PATH_CUSTOMIZATION, &lpPropValue)))

    {

    printf ("Fatal Error: failed to get property PR_AB_SEARCH_PATH_CUSTOMIZATION %d try to creat a new one n",hRes);

    SPropValue  spvEID_Ex;

    spvEID_Ex.ulPropTag = PR_AB_SEARCH_PATH_CUSTOMIZATION;

    spvEID_Ex.Value.l = 0;

    if (FAILED ( hRes = HrSetOneProp(lpProfSect, &spvEID_Ex)))

    {

    printf ("Fatal Error: failed to create a new one  %d n",hRes);

    lngReturn = -11;

    goto Cleanup;

    }

    }

  8. sureshh says:

    Hello Stephen Griffin,

    I am new to this and just wondering if there is equivalent code in C#.NET that we can use to implement similar functionality.

    Please advise.