ProcessStartInfo.WorkingDirectory : ProcessStartInfo « System.Diagnostics « C# / C Sharp by API






ProcessStartInfo.WorkingDirectory

  

using System;
using System.Diagnostics;

class MainClass
{
    public static void Main()
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "notepad.exe";
        startInfo.Arguments = "file.txt";
        startInfo.WorkingDirectory = @"C:\Temp";
        startInfo.WindowStyle = ProcessWindowStyle.Maximized;
        startInfo.ErrorDialog = true;

        Process process;
        try
        {
            process = Process.Start(startInfo);
            Console.WriteLine("Waiting 30 seconds for process to finish.");
            if (process.WaitForExit(30000))
            {
                Console.WriteLine("Process terminated.");
            }
            else
            {
                Console.WriteLine("Timed out waiting for process to end.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Could not start process.");
            Console.WriteLine(ex);
        }
    }
}

   
    
  








Related examples in the same category

1.new ProcessStartInfo()
2.ProcessStartInfo.Arguments
3.ProcessStartInfo.ErrorDialog
4.ProcessStartInfo.FileName
5.ProcessStartInfo.RedirectStandardOutput
6.ProcessStartInfo.UseShellExecute
7.ProcessStartInfo.WindowStyle