Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Program from C# - also specifying the working directory

Tags:

c#

.net

windows

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");
    }
like image 425
Dan Avatar asked Jun 04 '11 21:06

Dan


People also ask

How do I run a program?

In Windows to execute a program, double-click the executable file or double-click the shortcut icon pointing to the executable file. If you have a hard time double-clicking an icon, click the icon once to highlight it and then press Enter on the keyboard.


1 Answers

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);
like image 101
Dyppl Avatar answered Oct 31 '22 14:10

Dyppl