Author Topic: Find running instances of EA  (Read 5196 times)

Knut Paulsen

  • EA User
  • **
  • Posts: 82
  • Karma: +1/-0
    • View Profile
Find running instances of EA
« on: November 05, 2014, 11:36:41 pm »
Hi guys,

I want to find and access instances of EA already running on my computer. Using Microsoft.VisualBasic.Interaction.GetObject (from C#), I get one instance and it appears to be the 'oldest' one.

Any suggestion how I can find them all, and get hold of the repository object?

cheers
Knut

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Find running instances of EA
« Reply #1 on: November 06, 2014, 12:17:32 am »
You will likely have better chances if you ask this question at StackExchange.

To get the repository object of the instance just use this:
Code: [Select]
Dim Repository As EA.repository
Set EAapp = GetObject(, "EA.App")
Set Repository = EAapp.repository
(from my Scripting book)

q.
« Last Edit: November 06, 2014, 12:20:07 am by qwerty »

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Find running instances of EA
« Reply #2 on: November 06, 2014, 01:35:31 am »
To get all instances EA you can use the windows GetProcessByName method on the process class from which you can check

Code: [Select]
 For Each proc As Process In Process.GetProcessesByName("EA")
             ' processing....
             ' e.g. you can then get process information e.g. starttime of process
             startTime = proc.StartTime
  Next proc




May be worth downloading a copy of procexp within the systems internals suite (now within ms http://technet.microsoft.com/en-gb/sysinternals/bb545021.aspx ), if need to explore details of processes further.

Hope that helps.


« Last Edit: November 06, 2014, 09:25:58 pm by MrWappy »
EXploringEA - information, utilities and addins

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Find running instances of EA
« Reply #3 on: November 07, 2014, 05:53:56 pm »
Hi Knut,

I have this code in my EA Repository wrapper Model.cs which uses System.Diagnostics.Process.GetProcesses() to find all EA instances.
Code: [Select]
   /// <summary>
    /// the main EA window to use when opening properties dialogs
    /// </summary>
    public IWin32Window mainEAWindow
    {
          get
          {
                if //(true)
                      (this._mainEAWindow == null)
                {
                      List<Process> allProcesses = new List<Process>( Process.GetProcesses());
                           Process proc = allProcesses.Find(pr => pr.ProcessName == "EA");
                       //if we don't find the process then we set the mainwindow to null
                           if (proc == null
                               || proc.MainWindowHandle == null)
                       {
                             this._mainEAWindow = null;
                       }
                       else
                       {
                             //found it. Create new WindowWrapper
                             this._mainEAWindow  = new WindowWrapper(proc.MainWindowHandle);
                       }
                }
                 return this._mainEAWindow;
          }
    }
The proper way of connecting the the (oldest) EA instance in C# is using System.Runtime.InteropServices.Marshal.GetActiveObject() like this:
Code: [Select]
   /// Creates a model connecting to the first running instance of EA
    public Model(){
      object obj = Marshal.GetActiveObject("EA.App");
      global::EA.App eaApp = obj as global::EA.App;
      wrappedModel = eaApp.Repository;
    }

Regards

Geert

Knut Paulsen

  • EA User
  • **
  • Posts: 82
  • Karma: +1/-0
    • View Profile
Re: Find running instances of EA
« Reply #4 on: November 07, 2014, 06:34:33 pm »
Thanks guys, interesting :-)

Gert: let's say I have three EA.exe processes running and you find them via the allProcesses list. Is it then possible to access the EA repository object in all three processes? I could not quite see the connection between _mainEAWindow and the EA.Repository from your code sample.

Cheers
Knut

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Find running instances of EA
« Reply #5 on: November 07, 2014, 06:41:36 pm »
Imagine those instances as 3 independent users. It behaves the same. If you don't have locking you have a "first come, last served" behavior. IOW: the person clicking save at last will make the permanent changes. Eventually you'll see "underlying model has been changed".

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Find running instances of EA
« Reply #6 on: November 07, 2014, 07:39:13 pm »
Quote
Thanks guys, interesting :-)

Gert: let's say I have three EA.exe processes running and you find them via the allProcesses list. Is it then possible to access the EA repository object in all three processes? I could not quite see the connection between _mainEAWindow and the EA.Repository from your code sample.

Cheers
Knut

I guess it should be possible, but I haven't tried.
I would start by reading the documentation on the Marshal object and its methods
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getactiveobject(v=vs.100).aspx

Geert