Calling dism.exe from System.Diagnostics.Process Fails

前端 未结 4 1294
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 00:33

For enabling Microsoft-Hyper-V and Microsoft-Hyper-V-Management in Windows 2008 R2 Server(64bit), I\'m calling dism.exe as a process. The command I\'ve used is

4条回答
  •  [愿得一人]
    2020-12-19 01:19

    The thing is you need to call the appropriate dism.exe dependng on the system architecture.

    As @eric xu said, you need to resolve the path because it is not a real path. Below is the code that works for me. It basically detects the system architecture, resolves the path depending on the architecture and then calls the appropriate dism.exe.

    string system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "dism.exe");
    if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
    {
        // For 32-bit processes on 64-bit systems, %windir%\system32 folder
        // can only be accessed by specifying %windir%\sysnative folder.
        system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative", "dism.exe");
    }
    

    Source: File System Redirector

提交回复
热议问题