none
Closing Outlook session from .Net RRS feed

  • Question

  • Preferably in C# but VB is ok too, I can have multiple instances of Outlook sessions running and I want to close off just one instead of the whole entire app or process id. Can someone please help me with this?

    I have tried this and it doesn't work because it closes all the outlook sessions -
     System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
                    proc[0].Kill();

    This wont work as well -
    Outlook.Application app = new Outlook.Application();
    app.Quit()


    Problem is although you have multiple instances of outlook running but in the task manager you can see there is only one process for outlook unlike Excel.
    Friday, November 27, 2009 8:01 PM

Answers

  • Hello Ulam,

    Welcome to MSDN forums!

    Yes you'll find olny one Instance of Outlook.exe is running in your task manager, this is a by designed behavior, but you could see more than one Outlook main windows is displayed in your screen, these windows we call it a Explorer in Outlook, they all belongs to one Outlook session, if you need to close them we could get started form Outlook Object Model.

    Here's a Sample code:

    First, we need to obtain the running Outlook instance:

    Outlook.Application app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    Then, close the Explorer:
     app.Explorers[1].Close();

    Please check this link for Outlook Object Model Overview:
    http://msdn.microsoft.com/en-us/library/ms268893.aspx

    If you have any further questions, please feel free to follow up.

    Thanks.

    Tim Li
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Tuesday, December 1, 2009 2:52 AM
    Monday, November 30, 2009 3:02 AM

All replies

  • Hello Ulam,

    Welcome to MSDN forums!

    Yes you'll find olny one Instance of Outlook.exe is running in your task manager, this is a by designed behavior, but you could see more than one Outlook main windows is displayed in your screen, these windows we call it a Explorer in Outlook, they all belongs to one Outlook session, if you need to close them we could get started form Outlook Object Model.

    Here's a Sample code:

    First, we need to obtain the running Outlook instance:

    Outlook.Application app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    Then, close the Explorer:
     app.Explorers[1].Close();

    Please check this link for Outlook Object Model Overview:
    http://msdn.microsoft.com/en-us/library/ms268893.aspx

    If you have any further questions, please feel free to follow up.

    Thanks.

    Tim Li
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Tuesday, December 1, 2009 2:52 AM
    Monday, November 30, 2009 3:02 AM
  • Thank you Tim, your solution was perfect.
    Monday, November 30, 2009 4:07 PM