1

We're working on a WPF application that is going to work closely with other applications. Right now, it is working with Microsoft Excel.

I would like to run some custom code in the install of our WPF application that scans the user's computer and finds the location of Excel so that I can save it in the app.config file of our WPF program. Later, when we need to launch Excel to edit a file, I will use this path in the config file to pass into Process.Start().

I do not want to create an Excel Add-in or Template (not an option, so don't suggest this as an answer).

What security concerns do we have to worry about? Is this scheme "kosher"? What if I was trying to work with another app that did not have as much plug-ability as Excel. What methods would you suggest for locating and launching this app? Is it better to simply ask the user to locate the program instead of searching the file system for it?

Edit: Anyone want to discuss the general question? What if I am not launching Excel, but some other tool (iTunes, Audacity, etc)? No one has discussed or talked about the security question. Is it OK to search for the executable? Should I just ask the user where to find it?/Edit

Josh G
  • 14,068
  • 7
  • 62
  • 74

2 Answers2

2

The install path is in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot

14.0 might be different depending on the version.

Edit: In general, most installers will allow users to install the app anywhere they want so the app executable could be on any disk within any folder and therefore only a recursive search of all the folders on all the drives (after common installation paths are searched) would be a reliable method of finding an executable.

Hence, it is IMO better to present users with the browse dialog and allow them to locate the executable on their own.

Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
  • Works for Excel, but not ANY application we may work with. In addition, how would I know what version to look for? – Josh G Apr 07 '11 at 15:55
  • @Josh G, No application is required to insert registry data. There's no guarantee that you will find applications in one uniform fashion. Why not see how the applications your application will work with install by default and start from there? – Jeff LaFay Apr 07 '11 at 18:06
  • The key is to find a common interface / method for finding these executables. I assumed the file system was the only commonality. All programs have to reside somewhere in the file system. – Josh G Apr 07 '11 at 19:18
  • I think you should present the user with the browse dialog and allow him to find the executable. There is no reliable way to find the executable other than recursive search of all the folders on all the disks and that can take a very long time. For example, my M$ Office install root is D:\Programs\Office because my primary drive is a small SSD boot drive so all the larger and infrequently used apps are on the large D: drive. I have some other programs installed there that don't even have a registry entry so the recursive directory search would be the only way to find them... – Dean Kuga Apr 07 '11 at 19:32
  • This is perfect. If you could edit your answer and add this I will mark it as the answer. I think we will have to try to isolate the applications that DO have registry entries and use that. Otherwise the user will probably have to browse. – Josh G Apr 08 '11 at 11:56
0

as Path to Excel is registered in "PATH" Environment variable, i would have thought running "excel.exe" with filepath param should work.

or you can look up the registry and find out associated "Open With" apps with it and suggest to use which one to use (with optional make as default for you app).

Bek Raupov
  • 3,782
  • 3
  • 24
  • 42
  • "excel.exe" does not work for me. I opened CommandPrompt and typed it in and got "not recognized." – Josh G Apr 07 '11 at 15:56
  • "Open With" associated with what? Sounds like you are assuming that I will be opening a specified file. – Josh G Apr 07 '11 at 15:57
  • @Josh yeah, like when you do "Open With" on text file, it should all the list of available apps which can open it and i think it is stored in registry somewhere – Bek Raupov Apr 07 '11 at 16:04
  • Turns out you are right about "excel.exe," but that doesn't fit the general case. – Josh G Apr 07 '11 at 17:59