How should I configure paths to other exe files in my project?

46 Views Asked by At

I am working on a project that requires a .exe file to be executed by the application. The problem here is that I cannot guarantee that the file will always be in the same location on the user's machine, my app has no way of knowing where this .exe file is located.

So for example, my application needs to execute mongod.exe which is located (by default) in the following location: C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe.

The problem here is that this is not always the case, the user might have installed this application to a different place, so I can't assume that the path to the .exe file is always the same on every client.

Currently I am using the Settings.settings file to store a default file path to the file:

A setting in the Settings.settings file

The user can then either edit the app.config file or I could provide a UI to allow the user to change the file path.

So my question is, is there a better way?

1

There are 1 best solutions below

0
Pethusamy Venkatachalam On

Searching the path of the Mongodb.exe file in Registry can be useful. Try to find the exe path from the Registry entry.

RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\MongoDB\MongoDB Connector"); if (key != null) { Object o = key.GetValue("InstallPath"); }

Object o will give the path of MongoDB.exe file.

P.S.: If your application does not have rights to access the local machine's registry, then this approach won't work