C# 从C获取WindowsOptionalFeature失败
我正在尝试检查windows server 2012是否安装了IIS 我正在使用以下C语言程序。它在windows 7/10中运行良好,但在windows server 2012中出现错误C# 从C获取WindowsOptionalFeature失败,c#,powershell,iis,C#,Powershell,Iis,我正在尝试检查windows server 2012是否安装了IIS 我正在使用以下C语言程序。它在windows 7/10中运行良好,但在windows server 2012中出现错误 public static String ExecutePoswershellScript(String filepath) { log.Info(filepath); ProcessStartInfo startInfo = new ProcessStartInfo(); sta
public static String ExecutePoswershellScript(String filepath)
{
log.Info(filepath);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "powershell.exe";
startInfo.Arguments = filepath;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
log.Info(output);
string err = process.StandardError.ReadToEnd();
if (err.Length>0)
{
log.Error(err);
}
// log.Info(output + "");
process.WaitForExit();
process.Close();
return output;
}
错误如下
Get-WindowsOptionalFeature : An attempt was made to load a program with an incorrect format.
At line:1 char:64
+ ... ocess; Import-Module Dism; Get-WindowsOptionalFeature -Online | where ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WindowsOptionalFeature], CO
MException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.GetWindowsOptionalFeatureC
ommand
当我在windows server 2012中从powershell执行该命令时,它会工作,只有当我执行UINC时,它才会失败
PowerShell版本
Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
如果需要更改,请告知我打开IIS,右键单击应用程序池并转到“高级设置”,然后将“启用32位应用程序”更改为TRUE。重新启动你的网站,它应该会工作 或者在Visual Studio中,右键单击项目->在左侧窗格中单击“构建”选项卡,在平台目标下选择x86。在桌面上使用OSs
Get-WindowsOptionalFeature -Online
在服务器上使用OSs
Get-WindowsFeature *IIS*
你到底想查什么?从Windows注册表获取所有内容非常简单,因此调用PowerShell脚本不是最快的方法。@LexLi,发现很好,但如果未安装,我也想启用该功能,然后收到相同的错误