Reputation: 20644
In my application, the user can select a program:
D:/application/app.exe
I would like to execute it such that the same situation that I have to do on CMD, it will show:
C:/
then I have to do: D:
then:
D:/application/app.exe
The application can be only run on its folder for connecting with other libraries.
How can I make it possible to execute it from C# in such a way that it locate to the D:/application first and then execute: app.exe?
Thanks in advance.
Upvotes: 1
Views: 107
Reputation: 38590
See the WorkingDirectory property of ProcessStartInfo
. E.g.
Process.Start(new ProcessStartInfo {
WorkingDirectory = @"D:\application",
FileName = "app.exe"
}
Upvotes: 3
Reputation: 25201
The Path class can help you parse and manipulate your input path.
Path.GetPathRoot("D:\MyApp\App.exe") --> D:\
Path.GetDirectoryName("D:\MyApp\App.exe") --> D:\MyApp
Upvotes: 2
Reputation: 48985
ProcessStartInfo psi = new ProcessStartInfo(@"D:\application\app.exe") { WorkingDirectory = @"C:\" };
Process.Start(psi);
Upvotes: 1
Reputation: 160892
You can set the working directory when you start a new process:
Process.Start(new ProcessStartInfo()
{
FileName = @"D:\application\app.exe",
WorkingDirectory = @"D:\application",
//...
});
Upvotes: 3