diff --git a/winget-detect.ps1 b/winget-detect.ps1 index da64005..4d19501 100644 --- a/winget-detect.ps1 +++ b/winget-detect.ps1 @@ -7,7 +7,7 @@ $AppToDetect = "Notepad++.Notepad++" Function Get-WingetCmd { #Get WinGet Path (if admin context) - $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" + $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($ResolveWingetPath) { #If multiple version, pick last one $WingetPath = $ResolveWingetPath[-1].Path @@ -18,11 +18,7 @@ Function Get-WingetCmd { if ($WingetCmd) { $Script:Winget = $WingetCmd.Source } - #Get Winget Location in System context (WinGet < 1.17) - elseif (Test-Path "$WingetPath\AppInstallerCLI.exe") { - $Script:Winget = "$WingetPath\AppInstallerCLI.exe" - } - #Get Winget Location in System context (WinGet > 1.17) + #Get Winget Location in System context elseif (Test-Path "$WingetPath\winget.exe") { $Script:Winget = "$WingetPath\winget.exe" } diff --git a/winget-install.ps1 b/winget-install.ps1 index b92e69b..ee3e3a4 100644 --- a/winget-install.ps1 +++ b/winget-install.ps1 @@ -99,9 +99,9 @@ function Write-Log ($LogMsg, $LogColor = "White") { #Get WinGet Location Function function Get-WingetCmd { #Get WinGet Path (if admin context) - $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" + $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($ResolveWingetPath) { - #If multiple versions (when pre-release versions are installed), pick last one + #If multiple versions, pick last one $WingetPath = $ResolveWingetPath[-1].Path } #Get WinGet Location in User context @@ -114,7 +114,7 @@ function Get-WingetCmd { $Script:Winget = "$WingetPath\winget.exe" } else { - Write-Log "Winget not installed !" "Red" + Write-Log "Winget not installed or detected !" "Red" break } Write-Log "Using following Winget Cmd: $winget`n"