DISM call via C#

2.6k Views Asked by At
Process p = new Process();
p.StartInfo.FileName = "dism";
p.StartInfo.Arguments = "/online /get-packageinfo /packagename:WinEmb-File-Based-Write-Filter~31bf3856ad364e35~amd64~~6.1.7601.17514";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();

string output = p.StandardOutput.ReadToEnd();

p.WaitForExit();
p.Close();

I get output:

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.

Tried for FileName: "C:\WINDOWS\SYSTEM32\dism.exe" and "C:\WINDOWS\SYSWOW64\dism.exe"

and still getting same result.

Machine is running on Windows 7 Embedded.

EDIT: Have tried:

Calling dism.exe from System.Diagnostics.Process Fails

But still not working..

2

There are 2 best solutions below

0
On BEST ANSWER

Found solution! Make all projects/setups 64bit build.

And by following code its working:

ProcessStartInfo psi = new ProcessStartInfo("cmd");
psi.UseShellExecute = false;
psi.ErrorDialog = false;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;

Process plinkProcess = new Process();
plinkProcess.StartInfo = psi;
plinkProcess.Start();

StreamWriter inputWriter = plinkProcess.StandardInput;
StreamReader outputReader = plinkProcess.StandardOutput;
inputWriter.WriteLine("dism /online /get-packageinfo /packagename:WinEmb-File-Based-Write-Filter~31bf3856ad364e35~amd64~~6.1.7601.17514");
inputWriter.WriteLine("exit");
inputWriter.Flush();

plinkProcess.WaitForExit();

string strOutput = outputReader.ReadToEnd();

plinkProcess.Close();
0
On

Although already answered I've run into this issue multiple times. WinPE does not have compatibility with different architectures. So 64-bit WinPE has to run programs compiled for its architecture. As for dism there is a 64-bit and 32-bit versions when you install the WAIK or Windows Kits. 64-bit dism C:\Program Files\Windows AIK\Tools\amd64\Servicing\dism.exe 32-bit dism C:\Program Files\Windows AIK\Tools\x86\Servicing\dism.exe