Situation
I am trying to run a command-line tool, DISM.exe, programmatically. When I run it manually it works, but when I try to spawn it with the following:
var systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
var dism = new Process();
dism.StartInfo.FileName = Path.Combine(systemPath, "Dism.exe");
dism.StartInfo.Arguments = "/Online /Get-Features /Format:Table";
dism.StartInfo.Verb = "runas";
dism.StartInfo.UseShellExecute = false;
dism.StartInfo.RedirectStandardOutput = true;
dism.Start();
var result = dism.StandardOutput.ReadToEnd();
dism.WaitForExit();
Then my result
comes out as:
Error: 11
You cannot service a running 64-bit operating system with a 32-bit version of DISM. Please use the version of DISM that corresponds to your computer's architecture.
Problem
I'm actually already aware of what causes this: my project is set up to compile for an x86 platform. (See this question for example, although none of the answers mention this). However, unfortunately it is a requirement at the moment that we continue targeting this platform, I am not able to fix this by switching to Any CPU.
So my question is how to programmatically spawn a process in a way which is independent of the platform of its parent- i.e. keep my project targeting x86, but start a process which will target the correct platform for the machine it is on.