none
How to avoid Select Profile PopUp that comes when creating Outlook.Application object ? RRS feed

  • Question

  • Hi all,

              I am using Outlook Object library for Getting Items within PST file.When ever i am trying to create Outlook.Application

    Outlook internally prompting a select profile popup in multi profile Configured  outlook .I handled this scenario by editing registry value that found in @"Software\Microsoft\Exchange\Client\Options\PickLogonProfile to 0. But one of my friend told me registry change is not right thing to do. I also used namespace.Logon methos but still issue persist. Is there any other way to handle the scenario ? please advice.

    Thanks

    ***Hemant    


    H.S.Navarkar

    Wednesday, March 19, 2014 3:36 PM

Answers

  • Hello Hemant,

    Here is what MSDN states for the  Logon method:

    If Outlook is not running and you only want to start Outlook with the default profile, do not use the Logon method. A better alternative is shown in the following code example, InitializeMAPI: first, instantiate the Outlook Application object, then reference a default folder such as the Inbox. This has the side effect of initializing MAPI to use the default profile and to make the object model fully functional.

    Sub InitializeMAPI ()
    
        ' Start Outlook.
        Dim olApp As Outlook.Application
        Set olApp = CreateObject("Outlook.Application")
        
        ' Get a session object. 
        Dim olNs As Outlook.NameSpace
        Set olNs = olApp.GetNamespace("MAPI")
        
        ' Create an instance of the Inbox folder. 
        ' If Outlook is not already running, this has the side
        ' effect of initializing MAPI.
        Dim mailFolder As Outlook.Folder
        Set mailFolder = olNs.GetDefaultFolder(olFolderInbox)
    
        ' Continue to use the object model to automate Outlook.
    End Sub
    

    Wednesday, March 19, 2014 3:49 PM
  • Hi,

    You can use the Outlook object model to log on to a custom MAPI profile or the default profile.  When you first start Outlook on a computer, if you would like to programmatically log on to a custom profile (that is different from the default profile), you can use the Logon method of the NameSpace object. Specify the profile name as an argument for the Profile parameter.

    If Outlook is already running on a computer, you cannot change the current profile by starting another instance of Outlook on the same computer. Calling Logon and specifying a different profile does not change the current profile. This is because only one Outlook process can run at a time, and that Outlook process uses only one profile and supports only one MAPI session. Starting a subsequent instance of Outlook does not create a new process, but runs within the same initial Outlook process, and uses the same profile that the first Outlook instance uses.

    (From How to Log On to a Specific Profile in Outlook 2010)

    So please make sure there is no Outlook running on the computer, then you could use NameSpace.Logon Method to programmatically log on to a custom profile.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 26, 2014 8:16 AM
    Moderator

All replies

  • Hello Hemant,

    Here is what MSDN states for the  Logon method:

    If Outlook is not running and you only want to start Outlook with the default profile, do not use the Logon method. A better alternative is shown in the following code example, InitializeMAPI: first, instantiate the Outlook Application object, then reference a default folder such as the Inbox. This has the side effect of initializing MAPI to use the default profile and to make the object model fully functional.

    Sub InitializeMAPI ()
    
        ' Start Outlook.
        Dim olApp As Outlook.Application
        Set olApp = CreateObject("Outlook.Application")
        
        ' Get a session object. 
        Dim olNs As Outlook.NameSpace
        Set olNs = olApp.GetNamespace("MAPI")
        
        ' Create an instance of the Inbox folder. 
        ' If Outlook is not already running, this has the side
        ' effect of initializing MAPI.
        Dim mailFolder As Outlook.Folder
        Set mailFolder = olNs.GetDefaultFolder(olFolderInbox)
    
        ' Continue to use the object model to automate Outlook.
    End Sub
    

    Wednesday, March 19, 2014 3:49 PM
  • Hi Eugene, 

                      Can u please tell me how i can use CreateObject() method in c#.As CreateObject() Method is itself on Outlook.Application. 


    H.S.Navarkar

    Thursday, March 20, 2014 9:18 AM
  • Hello Hemant,

    See Activator.CreateInstance.

    Why do you need to look for any method and not just use the Application class ctor?

    Please take a look at the  How to automate Outlook and Word by using Visual C# .NET to create a pre-populated e-mail message that can be edited article for more information. Also I have found the C# app automates Outlook (CSAutomateOutlook) sample project for you.

    Finally, I'd recommend asking other questions in new forum threads. Thus, forum readers may easily recognize the question and answer. Feel free to ask your C# programming questions in the Visual C# forum.

    Thursday, March 20, 2014 12:09 PM
  • Hi,

    You can use the Outlook object model to log on to a custom MAPI profile or the default profile.  When you first start Outlook on a computer, if you would like to programmatically log on to a custom profile (that is different from the default profile), you can use the Logon method of the NameSpace object. Specify the profile name as an argument for the Profile parameter.

    If Outlook is already running on a computer, you cannot change the current profile by starting another instance of Outlook on the same computer. Calling Logon and specifying a different profile does not change the current profile. This is because only one Outlook process can run at a time, and that Outlook process uses only one profile and supports only one MAPI session. Starting a subsequent instance of Outlook does not create a new process, but runs within the same initial Outlook process, and uses the same profile that the first Outlook instance uses.

    (From How to Log On to a Specific Profile in Outlook 2010)

    So please make sure there is no Outlook running on the computer, then you could use NameSpace.Logon Method to programmatically log on to a custom profile.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 26, 2014 8:16 AM
    Moderator
  • In C++ and Office 365, I got the selection during CreateObject call and the function returns immediately before answer the selection dialog. Could this answer be updated to work correctly with latest Office?
    Thursday, September 24, 2020 2:55 AM
  • Do you mean you create an instance of the Outlook.Application object, but the call returns before a profile is selected?

    This is to be expected. If Application.Session == null, wait for the Application.MAPILogonCompleteEvent to fire.


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

    Thursday, September 24, 2020 3:19 AM