开发者

Open Program from C# - also specifying the working directory

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜