Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Marshal.GetActiveObject fails when triggered from a remote session

$
0
0

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);
            }



Viewing all articles
Browse latest Browse all 31927

Trending Articles