I want to start a process with the following path.
"ProgramFiles(x86)\Philips Speech\Device Control Center PDCC.exe"
When I type this into the console the process starts as expected but when I try to do it in code I get the following exception:
the system cannot find the file specified
This I my code so far:
var startInfo = new ProcessStartInfo("%ProgramFiles(x86)%\Philips Speech\Device Control Center PDCC.exe");
Debug.Assert(startInfo.EnvironmentVariables.ContainsKey("ProgramFiles(x86)")) //Is true
new Process(startInfo).Start(); //<- exception occures here
Does anybody have an idea if I can do this directly by giving the ProcessStartInfo class the environment variable or if I have to parse it before doing so?
string path = Environment.ExpanEnvironmentVariables("%ProgramFiles(x86)%\Philips Speech\Device Control Center PDCC.exe");
var startInfo = new ProcessStartInfo(path);
new Process(startInfo).Start();
This way you can use the variables (e.g. "%ProgramFiles(x86)%) and not depend on the folder being in C:\ or something.
You should use this to get the path to Program Files:
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
Special folders enum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With