Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit b1d9eda

Browse files
authored
Merge pull request #60 from KnifMelti/KnifDev
Modernized
2 parents 7b52dcf + 9e23468 commit b1d9eda

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

winget-detect.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $AppToDetect = "Notepad++.Notepad++"
77
Function Get-WingetCmd {
88

99
#Get WinGet Path (if admin context)
10-
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
10+
$ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
1111
if ($ResolveWingetPath) {
1212
#If multiple version, pick last one
1313
$WingetPath = $ResolveWingetPath[-1].Path
@@ -18,11 +18,7 @@ Function Get-WingetCmd {
1818
if ($WingetCmd) {
1919
$Script:Winget = $WingetCmd.Source
2020
}
21-
#Get Winget Location in System context (WinGet < 1.17)
22-
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe") {
23-
$Script:Winget = "$WingetPath\AppInstallerCLI.exe"
24-
}
25-
#Get Winget Location in System context (WinGet > 1.17)
21+
#Get Winget Location in System context
2622
elseif (Test-Path "$WingetPath\winget.exe") {
2723
$Script:Winget = "$WingetPath\winget.exe"
2824
}

winget-install.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ function Write-Log ($LogMsg, $LogColor = "White") {
9999
#Get WinGet Location Function
100100
function Get-WingetCmd {
101101
#Get WinGet Path (if admin context)
102-
$ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
102+
$ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
103103
if ($ResolveWingetPath) {
104-
#If multiple versions (when pre-release versions are installed), pick last one
104+
#If multiple versions, pick last one
105105
$WingetPath = $ResolveWingetPath[-1].Path
106106
}
107107
#Get WinGet Location in User context
@@ -114,7 +114,7 @@ function Get-WingetCmd {
114114
$Script:Winget = "$WingetPath\winget.exe"
115115
}
116116
else {
117-
Write-Log "Winget not installed !" "Red"
117+
Write-Log "Winget not installed or detected !" "Red"
118118
break
119119
}
120120
Write-Log "Using following Winget Cmd: $winget`n"

0 commit comments

Comments
 (0)