From 6322ef4b3620f6efbd69c564f789cf43e04b0cdb Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Mon, 10 Sep 2012 07:51:36 -0700 Subject: [PATCH] elevate permissions for list functinality and check os version and only use /all param if on win 8 or server 2012 --- nuget/tools/chocolateysetup.psm1 | 4 ++-- src/functions/Chocolatey-List.ps1 | 11 +++++++++-- src/functions/Chocolatey-WindowsFeatures.ps1 | 11 ++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/nuget/tools/chocolateysetup.psm1 b/nuget/tools/chocolateysetup.psm1 index 26d40f7..3059522 100644 --- a/nuget/tools/chocolateysetup.psm1 +++ b/nuget/tools/chocolateysetup.psm1 @@ -35,7 +35,7 @@ $nugetChocolateyUpdateAlias = Join-Path $chocolateyExePath 'cup.bat' $nugetChocolateyListAlias = Join-Path $chocolateyExePath 'clist.bat' $nugetChocolateyVersionAlias = Join-Path $chocolateyExePath 'cver.bat' $nugetChocolateyWebPiAlias = Join-Path $chocolateyExePath 'cwebpi.bat' -$nugetChocolateyWinFeaturesAlias = Join-Path $chocolateyExePath 'cwinfeatures.bat' +$nugetChocolateyWindowsFeaturesAlias = Join-Path $chocolateyExePath 'cwindowsfeatures.bat' $nugetChocolateyCygwinAlias = Join-Path $chocolateyExePath 'ccygwin.bat' $nugetChocolateyPythonAlias = Join-Path $chocolateyExePath 'cpython.bat' $nugetChocolateyGemAlias = Join-Path $chocolateyExePath 'cgem.bat' @@ -79,7 +79,7 @@ Write-Host "Creating `'$nugetChocolateyWebPiAlias`' so you can call 'chocolatey SET DIR=%~dp0% ""$nugetChocolateyPath\chocolatey.cmd"" webpi %*" | Out-File $nugetChocolateyWebPiAlias -encoding ASCII -Write-Host "Creating `'$nugetChocolateyWinFeaturesAlias`' so you can call 'chocolatey windowsfeatures' from a shortcut of 'cwinfeatures'." +Write-Host "Creating `'$nugetChocolateyWindowsFeaturesAlias`' so you can call 'chocolatey windowsfeatures' from a shortcut of 'cwinfeatures'." "@echo off SET DIR=%~dp0% ""$nugetChocolateyPath\chocolatey.cmd"" windowsfeatures %*" | Out-File $nugetChocolateyWindowsFeaturesAlias -encoding ASCII diff --git a/src/functions/Chocolatey-List.ps1 b/src/functions/Chocolatey-List.ps1 index 8753ad3..da3244b 100644 --- a/src/functions/Chocolatey-List.ps1 +++ b/src/functions/Chocolatey-List.ps1 @@ -9,8 +9,15 @@ param( $webpiArgs ="/c webpicmd /List /ListOption:All" & cmd.exe $webpiArgs } elseif ($source -like 'windowsfeatures') { - $windowsFeaturesArgs ="/c dism /online /get-features /format:table" - & cmd.exe $windowsFeaturesArgs + $chocoInstallLog = Join-Path $nugetChocolateyPath 'chocolateyWindowsFeaturesInstall.log'; + Remove-LastInstallLog $chocoInstallLog + $windowsFeaturesArgs ="/c dism /online /get-features /format:table | Tee-Object -FilePath `'$chocoInstallLog`';" + Start-ChocolateyProcessAsAdmin "cmd.exe $windowsFeaturesArgs" -nosleep + Create-InstallLogIfNotExists $chocoInstallLog + $installOutput = Get-Content $chocoInstallLog -Encoding Ascii + foreach ($line in $installOutput) { + Write-Host $line + } } else { $srcArgs = Get-SourceArguments $source diff --git a/src/functions/Chocolatey-WindowsFeatures.ps1 b/src/functions/Chocolatey-WindowsFeatures.ps1 index 2a849ba..ee8778c 100644 --- a/src/functions/Chocolatey-WindowsFeatures.ps1 +++ b/src/functions/Chocolatey-WindowsFeatures.ps1 @@ -2,7 +2,7 @@ function Chocolatey-WindowsFeatures { param( [string] $packageName ) - Write-Debug "Running 'Chocolatey-WindowsFeatures' for $packageName with installerArguments:`'$installerArguments`'"; + Write-Debug "Running 'Chocolatey-WindowsFeatures' for $packageName"; @" $h1 @@ -12,12 +12,17 @@ $h1 $chocoInstallLog = Join-Path $nugetChocolateyPath 'chocolateyWindowsFeaturesInstall.log'; Remove-LastInstallLog $chocoInstallLog + $osVersion = (Get-WmiObject -class Win32_OperatingSystem).Version - $packageArgs = "/c DISM /Online /NoRestart /Enable-Feature /all /FeatureName:$packageName" + $packageArgs = "/c DISM /Online /NoRestart /Enable-Feature" + if($osVersion -ge 6.2) { + $packageArgs += " /all" + } + $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..." $statements = "cmd.exe $packageArgs | Tee-Object -FilePath `'$chocoInstallLog`';" - Start-ChocolateyProcessAsAdmin "$statements" -minimized -nosleep + Start-ChocolateyProcessAsAdmin "$statements" -minimized -nosleep -validExitCodes @(0,1) Create-InstallLogIfNotExists $chocoInstallLog $installOutput = Get-Content $chocoInstallLog -Encoding Ascii