开发者

Open Program from C# - also specifying the working directory

开发者 https://www.devze.com 2023-03-11 14:08 出处:网络
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:

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

精彩评论

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

关注公众号