I'm trying to call chrome.exe inside a C# program by using System.Diagnostics.Process namespace.
my chrome.exe is located inside path C:\Program Files (x86)\Google\Chrome\Application
if I call RunProc function by passing bellow parameters - (keep absolute path of the exe and keep WorkingDirectory empty)
("C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe" , "https://www.google.com", "") it works just fine.
But, with parameters -
("Chrome.exe , "https://www.google.com", "C:\Program Files (x86)\Google\Chrome\Application") it gives exception at step proc.Start(); stating - The system cannot find the file specified.
I also tried writing WorkingDirectory = workingDir while initializing StartInfo but still looking for solutions.
class Program
{
static void Main(string[] args)
{
RunProc(@"chrome.exe", @"https://www.google.com", @"C:\Program Files (x86)\Google\Chrome\Application");
}
static bool RunProc(string exe, string args, string workingDir)
{
Process proc = new Process
{
StartInfo =
{
FileName = exe,
CreateNoWindow = true,
RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
Arguments = args,
//WorkingDirectory = workingDir
}
};
if (!string.IsNullOrEmpty(workingDir))
{
proc.StartInfo.WorkingDirectory = workingDir;
}
proc.Start();
proc.StandardInput.WriteLine(args);
proc.StandardInput.Flush();
proc.StandardInput.Close();
return true;
}
}