Search code examples
c#wpfdism

DISM call via C#


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..


Solution

  • 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();