From 9c90fa2085a0830e547b62f9b7dafd4d833f337a Mon Sep 17 00:00:00 2001 From: Julian Easterling Date: Thu, 19 Dec 2013 12:01:12 -0500 Subject: [PATCH 1/2] Fixed Issue where the 32-bit DISM will be called on a 64-bit OS when running a 32-bit shell/process --- src/functions/Chocolatey-WindowsFeatures.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/functions/Chocolatey-WindowsFeatures.ps1 b/src/functions/Chocolatey-WindowsFeatures.ps1 index 0f36a3d..ad919c5 100644 --- a/src/functions/Chocolatey-WindowsFeatures.ps1 +++ b/src/functions/Chocolatey-WindowsFeatures.ps1 @@ -9,16 +9,24 @@ param( $chocoInstallLog = Join-Path $nugetChocolateyPath 'chocolateyWindowsFeaturesInstall.log'; Append-Log $chocoInstallLog - + + # On a 64-bit OS, the 32-bit version of DISM can be called if the powershell host is 32-bit and results in an error... + # To fix this, we need to use a not-well know feature of 32-bit shells running on 64-bit OS, the "sysnative" directory. + if (Test-Path "$env:WinDir\sysnative\dism.exe") { + $dism = "$env:WinDir\sysnative\dism.exe" + } else { + $dism = "$env:WinDir\System32\dism.exe" + } + $checkStatement=@" -`$dismInfo=(DISM /Online /Get-FeatureInfo /FeatureName:$packageName) +`$dismInfo=(cmd /c `"$dism /Online /Get-FeatureInfo /FeatureName:$packageName`") if(`$dismInfo -contains 'State : Enabled') {return} if(`$dismInfo -contains 'State : Enable Pending') {return} "@ $osVersion = (Get-WmiObject -class Win32_OperatingSystem).Version - $packageArgs = "/c DISM /Online /NoRestart /Enable-Feature" + $packageArgs = "/c $dism /Online /NoRestart /Enable-Feature" if($osVersion -ge 6.2) { $packageArgs += " /all" } From f849a61fe38a0334ef9ddc899ec258493f68edfc Mon Sep 17 00:00:00 2001 From: Julian Easterling Date: Thu, 19 Dec 2013 12:02:29 -0500 Subject: [PATCH 2/2] Fixed issue 378 where DISM is missing because of a missing newline in the command passed to the elevated shell and by specifying the exact path to the DISM tool instead of relying of the path of the system. --- src/functions/Chocolatey-WindowsFeatures.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/Chocolatey-WindowsFeatures.ps1 b/src/functions/Chocolatey-WindowsFeatures.ps1 index ad919c5..3a835ae 100644 --- a/src/functions/Chocolatey-WindowsFeatures.ps1 +++ b/src/functions/Chocolatey-WindowsFeatures.ps1 @@ -33,7 +33,7 @@ if(`$dismInfo -contains 'State : Enable Pending') {return} $packageArgs += " /FeatureName:$packageName" Write-Host "Opening minimized PowerShell window and calling `'cmd.exe $packageArgs`'. If progress is taking a long time, please check that window. It also may not be 100% silent..." -ForegroundColor $Warning -BackgroundColor Black - $statements = $checkStatement + "cmd.exe $packageArgs | Tee-Object -FilePath `'$chocoInstallLog`';" + $statements = $checkStatement + "`ncmd.exe $packageArgs | Tee-Object -FilePath `'$chocoInstallLog`';" Start-ChocolateyProcessAsAdmin "$statements" -minimized -nosleep -validExitCodes @(0,1) Create-InstallLogIfNotExists $chocoInstallLog