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开发者_如何学Python)
{
System.Diagnostics.Process.Start(@"update\update.exe");
}
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);
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);
精彩评论