Reputation: 133
I have some code that launches an external program, although is it possible to specify the working directory, as the external program is a console program:
Code:
private void button5_Click_2(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"update\update.exe");
}
Upvotes: 13
Views: 9707
Reputation: 12381
Yes, it's possible, use ProcessStartInfo
object to specify all the params you need and then just pass it to the Start
method like that:
...
using System.Diagnostics;
...
var psi = new ProcessStartInfo(@"update\update.exe");
psi.WorkingDirectory = @"C:\workingDirectory";
Process.Start(psi);
Upvotes: 26
Reputation: 6378
You can specify the Working Directory using ProcessStartInfo.WorkingDirectory.
...
using System.Diagnostics;
...
var processStartInfo = new ProcessStartInfo(@"explorer.exe");
processStartInfo.WorkingDirectory = @"C:\";
var process = Process.Start(processStartInfo);
Upvotes: 6