Programatically locating office executables

Add-in Express™ Support Service
That's what is more important than anything else

Programatically locating office executables
Finding the right way for launching office apps programatically 
Gavin Howard




Posts: 8
Joined: 2016-12-01
We're in the process of creating our end to end tests for the excel add-in we have been building and have been having a lot of success using MStest in conjunction with Coded UI tests to drive our add-in panels. What we have been struggling with though, on our test boxes and local developer machines is finding a way to get the correct path to excel.exe programmatically in C#.

We first tried to use interop services by doing something like:

     public void UIExcelInit()
        {
            try
            {
                Excel.Application app = new Excel.Application();
                interopExcelPath = app.Path;
                app.Quit();
            }
            catch(Exception e)
            {
                Console.WriteLine("There has been an issue locating Excel.exe in this context." + e.Message);
                throw;
            }
            finally
            {
                if (app != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
            }
        }



However, this seems to launch an extra few excel.exe process for us which are not cleaned up very quickly before the tests commence execution.

Alternately, we could use the registry entries - but in some contexts the user under which the tests are executing will not have privileges to access the registry.

Is there any way either from some standard C# methodology, Interop services or the ADX libraries to get the path to execl.exe programmatically?
Posted 13 Nov, 2017 09:56:46 Top
Andrei Smolin


Add-in Express team


Posts: 14976
Joined: 2006-05-11
Hello Gavin,

Gavin Howard writes:
However, this seems to launch an extra few excel.exe process for us which are not cleaned up very quickly before the tests commence execution.


Turn off all COM add-ins off for EXCEL.EXE to quit. If the issue occurs with your add-in turned on, this may be a result of your add-in leaving some COM objects unreleased; see Why doesn't Excel quit.

Gavin Howard writes:
Is there any way either from some standard C# methodology, Interop services or the ADX libraries to get the path to execl.exe programmatically?


System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName?

Add-in Express doesn't search excel.exe. You may also need totake into account the possibility to have several Excel versions installed.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2017 04:05:59 Top