Skip to content

Commit

Permalink
Fix detection method for multiple winged installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanitho committed May 5, 2022
1 parent 89dbd9c commit 53cf187
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions winget-detect.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@ $AppToDetect = "Notepad++.Notepad++"

<# FUNCTIONS #>

function Get-WingetCmd {
#Get WinGet Location in User context
Function Get-WingetCmd {

#Get WinGet Path (if admin context)
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
if ($ResolveWingetPath){
#If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path
}

#Get Winget Location in User context
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
if ($WingetCmd){
$Script:winget = $WingetCmd.Source
$Script:Winget = $WingetCmd.Source
}
#Get WinGet Location in System context (WinGet < 1.17)
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){
$Script:winget = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select-Object -ExpandProperty Path
#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)
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){
$Script:winget = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select-Object -ExpandProperty Path
#Get Winget Location in System context (WinGet > 1.17)
elseif (Test-Path "$WingetPath\winget.exe"){
$Script:Winget = "$WingetPath\winget.exe"
}
else{
break
}
}


<# MAIN #>

#Get WinGet Location Function
Expand Down

0 comments on commit 53cf187

Please sign in to comment.