Programmatically start a process regardless of platform

Situation

I am trying to run a command line tool tool, DISM.exe, programmatically. When I run it manually, it works, but when I try to create 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 appears as:

Error: 11

You cannot service a 64-bit operating system with a 32-bit version of DISM. Please use the version of DISM that matches your computer architecture.

Problem

I really already know what causes this: my project is configured to compile for the x86 platform. (See this question , although none of the answers mention this.) However, unfortunately, at the moment we insist that we continue to aim at this platform, I can not fix it by switching to any CPU.

So my question is how to programmatically start a process in a way that does not depend on the platform of its parent, i.e. save my project with x86 targeting, but run a process that will target the correct platform for the machine it is running on.

+6
source share
2 answers

although I am running the correct DSIM.exe in System32

But this is not so. This is the point. The file system redirector lies in 32-bit processes, so when you request System32 from an x86 process, you actually get the file from SysWow64 . If you want to access the 64-bit version of exe, you need to request it through %windir%\sysnative

( %windir% SpecialFolder.Windows )

+4
source

Although it does not answer your question about starting a 64-bit process with a 32-bit version, an alternative approach to your main problem is to ask WMI to get the required information. You can view additional features or list Server Features

This answer gives general information about running a WMI request with C #.

You can also test and install Windows functions from powershell , which you could run from your program instead of running DISM.

+2
source

All Articles