Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching an .exe from the current folder sometimes fails

Tags:

c#

process

I have an app launching an executable which is in the same folder as that app, by doing:

            Process procStarter = new Process();
            procStarter.StartInfo.FileName = "OtherApp.exe";
            procStart.Start();

which works fine, until I used a file open or file save dialog in my app. Then it can't find OtherApp.exe.

Does that seem normal? Can I just fix it by adding the current folder to StartInfo.Filename (and how do I obtain the current folder)?

like image 605
Warpin Avatar asked Dec 09 '22 17:12

Warpin


1 Answers

Using the file dialog probably changes the current directory of your process. To access a file in the same folder as your current executable you can use the following code:

string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path = Path.Combine(path, "OtherApp.exe");
like image 160
Dirk Vollmar Avatar answered Dec 20 '22 20:12

Dirk Vollmar