从System.Diagnostics.Process调用dism.exe失败 [英] Calling dism.exe from System.Diagnostics.Process Fails
问题描述
为在Windows 2008 R2 Server(64位)中启用Microsoft-Hyper-V和Microsoft-Hyper-V-Management,我将dism.exe称为进程.我使用的命令是
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
Dism.exe/online/Get-FeatureInfo /FeatureName:Microsoft-Hyper-V
Dism.exe /online /Get-FeatureInfo /FeatureName:Microsoft-Hyper-V
Dism.exe/online/Get-FeatureInfo /FeatureName:Microsoft-Hyper-V-Management-Clients
Dism.exe /online /Get-FeatureInfo /FeatureName:Microsoft-Hyper-V-Management-Clients
当我从命令行执行此操作时,此方法工作正常,但是当我尝试通过代码执行该操作时,该方法失败.我已经在C:\ Windows \ SysWoW64文件夹下尝试过Dism.exe的64位版本,但它也失败了.这是我收到的错误消息,
This works fine when I execute this from the command line but it fails when I try to execute it through my code. I've tried the 64bit version of Dism.exe under the C:\Windows\SysWoW64 folder but it fails too. Here is the error message I get,
您不能为正在运行的64位服务 带有32位版本的操作系统 的DISM.请使用的版本 与您的DISM相对应的DISM 计算机的体系结构.
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.
我在这里想念什么?
更新:SLaks是正确的,但是问题出在默认情况下,MS Visual Studio Express Edition的目标是x86,我必须在.csproj文件中手动编辑该文件到AnyCPU才能使其正常工作.
UPDATE: SLaks was right, but the issue turned out to be that MS Visual studio express edition by default targets x86 which I had to manually edit in the .csproj file to AnyCPU to make it work.
推荐答案
Because you're running in a 32-bit process, you're getting redirected to the 32-bit version in SysWoW64
运行%WINDIR%\SysNative\dism.exe
以防止重定向.
这篇关于从System.Diagnostics.Process调用dism.exe失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!