none
How to get all outlook profiles using C# RRS feed

  • Question

  • Hi ,

    I want to display all the outlook profiles  in a listbox. On selecting one profile, all contacts belongs to the selected outlook profile  should
    be displayed.

    I am able to access contacts using Microsoft.Office.Interop for default profile with following code:

    Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
    NameSpace olMAPI = outlookApp.GetNamespace("MAPI");

    MAPIFolder
    folderContacts = olMAPI.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

    foreach (ContactItem contact in folderContacts.Items)

    {

    ...

    }

    But I am not able to get all outlook profiles and associated contacts. L

    How can I display all the profiles in the listbox and how can I get outlook contact associated with the selected profile.

    Please help with code sample if possible.

    Thanking in advance.


    Monday, March 19, 2012 8:35 AM

Answers

  • Firsly, keep in mind that Outlook is a singleton, you cannot have 2 instances of outlook.exe running for the same local user at the same time.

    Secondly, the list of profiles is stored in HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles

    You can either use one profile at a time, make sure Outlook is completely unloaded, then start a new instance of Outlook and make it log to a different profile.

    You can also use multiple profiles in Extended MAPI (MAPILogonEx) or Redemption (RDOSession.Logon).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 19, 2012 2:48 PM
  • With Outlook you have to exit it completely and re-start it using a different profile. Outlook can't switch profiles.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "PratibhaS" <=?utf-8?B?UHJhdGliaGFT?=> wrote in message news:0a65f75e-e9cc-42a6-823e-7e87cad32996...
     

    Thanks Dmitry for your valuable response!!

    Now I am able to fetch all profiles from registry and display list of all profiles in a combobox control.

    I want to switch between profiles programmatically on changing the selected profile in combo.

    I tried Logon method of namespace:

    NameSpaceolMAPI = outlookApp.GetNamespace("MAPI");

    olMAPI.Logon(this.SelectedProfile, Missing.Value, false, true);

     but this is not working :(

    Is there any way to load or unload selected profile programmatically using C# and fetch contacts for selected profile?

    Please help.


    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 1:41 PM
    Moderator

All replies

  • I wrote in onother lang, but I found this code Outlook profile Switching


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Monday, March 19, 2012 9:05 AM
  • Firsly, keep in mind that Outlook is a singleton, you cannot have 2 instances of outlook.exe running for the same local user at the same time.

    Secondly, the list of profiles is stored in HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles

    You can either use one profile at a time, make sure Outlook is completely unloaded, then start a new instance of Outlook and make it log to a different profile.

    You can also use multiple profiles in Extended MAPI (MAPILogonEx) or Redemption (RDOSession.Logon).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 19, 2012 2:48 PM
  •  

    Thanks Dmitry for your valuable response!!

    Now I am able to fetch all profiles from registry and display list of all profiles in a combobox control.

    I want to switch between profiles programmatically on changing the selected profile in combo.

    I tried Logon method of namespace:

    NameSpaceolMAPI = outlookApp.GetNamespace("MAPI");

    olMAPI.Logon(this.SelectedProfile, Missing.Value, false, true);

     but this is not working :(

    Is there any way to load or unload selected profile programmatically using C# and fetch contacts for selected profile?

    Please help.

    Wednesday, March 21, 2012 12:18 PM
  • With Outlook you have to exit it completely and re-start it using a different profile. Outlook can't switch profiles.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "PratibhaS" <=?utf-8?B?UHJhdGliaGFT?=> wrote in message news:0a65f75e-e9cc-42a6-823e-7e87cad32996...
     

    Thanks Dmitry for your valuable response!!

    Now I am able to fetch all profiles from registry and display list of all profiles in a combobox control.

    I want to switch between profiles programmatically on changing the selected profile in combo.

    I tried Logon method of namespace:

    NameSpaceolMAPI = outlookApp.GetNamespace("MAPI");

    olMAPI.Logon(this.SelectedProfile, Missing.Value, false, true);

     but this is not working :(

    Is there any way to load or unload selected profile programmatically using C# and fetch contacts for selected profile?

    Please help.


    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 1:41 PM
    Moderator