13

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");
    }
Dan
  • 133
  • 1
  • 4

2 Answers2

25

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);
umlcat
  • 4,091
  • 3
  • 19
  • 29
Dyppl
  • 12,161
  • 9
  • 47
  • 68
6

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);
umlcat
  • 4,091
  • 3
  • 19
  • 29
Richard Slater
  • 6,313
  • 4
  • 53
  • 81