none
Marshal.GetActiveObject fails when triggered from a remote session RRS feed

  • Question

  • I am working on automating a flow on Outlook (using Outlook APIs).

    I am trying to get the active instance of Outlook from a csharp executable. My intention is to create an event in the default calendar.

    When I run the Csharp executable locally on the machine, everything works like a charm.

    But when I run the same exe through an ssh session from a mac (ssh win_user@win_host "test.exe") I get the COM Exception 0x800401E3 indicating that no instance of outlook is currently running. So my code ends up creating a new instance of outlook, where it goes on to create my event. Later, after killing/restarting outlook a couple of times, I randomly see the events created remotely in my calendar.

    I am unsure about why I am not able to get an instance of outlook in the very same executable when triggered remotely. Are the ROT's different? I made sure that I ran outlook as the same win_user as the one I use - to login through ssh.

    I also locally created another win_user2 and used the "runas/user:win_user test.exe" command with the same effect. - Com Exception indicating no instance running.

     try
                {
                    olApp = (Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    try
                    {
                        Console.WriteLine(ex);
                        Console.WriteLine("Launching Outlook");
                        olApp = new Outlook.Application();
                    }
                    catch (Exception applaunchex)
                    {
                        Console.WriteLine("There was an exception while launching outlook" + applaunchex);
                        return 1;
                    }
                }
                if (olApp != null)
                {
                    Console.WriteLine("Outlook is up and running");
                    System.Threading.Thread.Sleep(5000);
                }


    • Edited by k_phoenix Wednesday, June 12, 2013 8:04 PM
    • Moved by Lisa Zhu Thursday, June 13, 2013 7:45 AM outlook dev related
    Wednesday, June 12, 2013 7:48 PM

Answers

  • you will have to check if one of the processes (either outlook or your app in remote session/runs as) is not evelated - elevated and non elevated apps cannot communicate, this is by design.
    Thursday, June 13, 2013 2:59 PM