Launch WPF application using Process.Start
10,273
I fixed the problem this way:
Process proc = new Process();
proc.StartInfo.FileName = programPath;
proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(programPath);
proc.Start();
The trick was to set the working directory to the path of the WPF application, rather than the working directory of the launching application.
Author by
Christian Stewart
Updated on June 04, 2022Comments
-
Christian Stewart over 1 year
I am attempting to launch a wpf application using
Process.Start
. When I launch the process by double-clicking it inexplorer.exe
, it launches properly; however, when I try to use the following code snippet:var programPath = @"C:\Users\user\Documents\Program Directory\program.exe"; if(!File.Exists(programPath)) { MessageBox.Show("The program.exe file does not exist! Cannot launch."); return; } Process.Start(programPath);
My WPF process flashes in the task manager briefly before immediately closing.
-
AlSki almost 10 yearsIs this specific to your program? What happens if you run it with an invalid working directory via some other method (such as creating a shortcut and then changing the path or running it from a cmd)