Reputation: 225
I have a C# program that is running and I want to launch another executable in different directory.
I have this code on event:
string path = "Y:\Program\test.exe";
Process.Start(path);
Problem is that in order for program to work right it need to take information from settings.ini where the exe file is located but it takes settings.ini from program folder with which I am trying to launch second program. test.exe is working fine when I am opening it from its folder by double click. What could be the problem?
Upvotes: 3
Views: 62
Reputation: 149518
You need to tell the process what the working directory is via ProcessStartInfo.WorkingDirectory
:
var processStartInfo = new ProcessStartInfo
{
WorkingDirectory = @"Y:\Program",
FileName = @"Y:\Program\test.exe",
};
Process.Start(processStartInfo);
Edit:
In order to get the directory from the user, you can use DirectoryInfo.FullName
:
var userFileInfo = new FileInfo(userInsertedVariableHere);
var parentDirectory = userFileInfo.Directory.FullName;
Upvotes: 2