From 0db7cf45169c21636b83d9f12ae8f5a2a39309c2 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 9 Sep 2023 22:30:12 +0200 Subject: [PATCH 1/6] $WingetUpdatePath if write prohibited and dependencies in SYSTEM context --- Winget-AutoUpdate-Install.ps1 | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index d4a5b2f..ef8b2a3 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -194,16 +194,39 @@ function Install-WinGet { } Else { + #Installing Dependencies in SYSTEM context + #Download Microsoft.UI.Xaml.2.7 + if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) { + #Install + $UiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0" + $UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip" + Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip + Expand-Archive -Path $UiXamlZip -DestinationPath "$WingetUpdatePath\extracted" -Force + Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null + Remove-Item -Path $UiXamlZip -Force + Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse + } + + #Download Microsoft.VCLibs.140.00.UWPDesktop + if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) { + #Install + $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" + $VCLibsFile = "$WingetUpdatePath\Microsoft.VCLibs.x64.14.00.Desktop.appx" + Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile + Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null + Remove-Item -Path $VCLibsFile -Force + } + #Download WinGet MSIXBundle Write-Host "-> Not installed. Downloading WinGet..." $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient - $WebClient.DownloadFile($WinGetURL, "$PSScriptRoot\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") + $WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") - #Install WinGet MSIXBundle + #Install WinGet MSIXBundle in SYSTEM context try { Write-Host "-> Installing Winget MSIXBundle for App Installer..." - Add-AppxProvisionedPackage -Online -PackagePath "$PSScriptRoot\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null + Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Write-Host "Installed Winget MSIXBundle for App Installer" -ForegroundColor Green } catch { @@ -211,7 +234,7 @@ function Install-WinGet { } #Remove WinGet MSIXBundle - Remove-Item -Path "$PSScriptRoot\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue + Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue } From 843fc86acb9af89666026885a3811140a7a15045 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 9 Sep 2023 23:55:29 +0200 Subject: [PATCH 2/6] Try-Catch and Write-Host --- Winget-AutoUpdate-Install.ps1 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index ef8b2a3..ebf2c88 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -202,18 +202,29 @@ function Install-WinGet { $UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip" Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip Expand-Archive -Path $UiXamlZip -DestinationPath "$WingetUpdatePath\extracted" -Force - Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null + try { + Write-Host "-> Installing Microsoft.UI.Xaml.2.7..." + Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null + } + catch { + Write-Host "Failed to intall Wicrosoft.UI.Xaml.2.7..." -ForegroundColor Red + } Remove-Item -Path $UiXamlZip -Force Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse } #Download Microsoft.VCLibs.140.00.UWPDesktop if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) { - #Install $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" $VCLibsFile = "$WingetUpdatePath\Microsoft.VCLibs.x64.14.00.Desktop.appx" Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile - Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null + try { + Write-Host "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..." + Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null + } + catch { + Write-Host "Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." -ForegroundColor Red + } Remove-Item -Path $VCLibsFile -Force } From 37137178900b9b88fb23e054817b6b6ee87b3cff Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 10 Sep 2023 00:35:25 +0200 Subject: [PATCH 3/6] Better info --- Winget-AutoUpdate-Install.ps1 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index ebf2c88..b4ad390 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -163,10 +163,10 @@ function Install-Prerequisites { Write-host "-> Installing VC_redist.$OSArch.exe..." Start-Process -FilePath $Installer -Args "/quiet /norestart" -Wait Remove-Item $Installer -ErrorAction Ignore - Write-host "-> MS Visual C++ 2015-2022 installed successfully" -ForegroundColor Green + Write-host "MS Visual C++ 2015-2022 installed successfully" -ForegroundColor Green } catch { - Write-host "-> MS Visual C++ 2015-2022 installation failed." -ForegroundColor Red + Write-host "MS Visual C++ 2015-2022 installation failed." -ForegroundColor Red Start-Sleep 3 } } @@ -189,15 +189,16 @@ function Install-WinGet { #Current: v1.5.1881 = 1.20.1881.0 = 2023.707.2257.0 If ([Version]$TestWinGet.Version -ge "2023.707.2257.0") { - Write-Host "WinGet is Installed" -ForegroundColor Green + Write-Host "Winget is Installed" -ForegroundColor Green } Else { - #Installing Dependencies in SYSTEM context - #Download Microsoft.UI.Xaml.2.7 + Write-Host "-> Winget is not installed:" + + #Downloading and Installing Dependencies in SYSTEM context if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) { - #Install + Write-Host "-> Downloading Microsoft.UI.Xaml.2.7..." $UiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0" $UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip" Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip @@ -205,6 +206,7 @@ function Install-WinGet { try { Write-Host "-> Installing Microsoft.UI.Xaml.2.7..." Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null + Write-host "Microsoft.UI.Xaml.2.7 installed successfully" -ForegroundColor Green } catch { Write-Host "Failed to intall Wicrosoft.UI.Xaml.2.7..." -ForegroundColor Red @@ -213,14 +215,15 @@ function Install-WinGet { Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse } - #Download Microsoft.VCLibs.140.00.UWPDesktop if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) { + Write-Host "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..." $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" $VCLibsFile = "$WingetUpdatePath\Microsoft.VCLibs.x64.14.00.Desktop.appx" Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile try { Write-Host "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..." Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null + Write-host "Microsoft.VCLibs.140.00.UWPDesktop installed successfully" -ForegroundColor Green } catch { Write-Host "Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." -ForegroundColor Red @@ -229,7 +232,7 @@ function Install-WinGet { } #Download WinGet MSIXBundle - Write-Host "-> Not installed. Downloading WinGet..." + Write-Host "-> Downloading Winget MSIXBundle for App Installer..." $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") @@ -238,7 +241,7 @@ function Install-WinGet { try { Write-Host "-> Installing Winget MSIXBundle for App Installer..." Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null - Write-Host "Installed Winget MSIXBundle for App Installer" -ForegroundColor Green + Write-host "Winget MSIXBundle for App Installer installed successfully" -ForegroundColor Green } catch { Write-Host "Failed to intall Winget MSIXBundle for App Installer..." -ForegroundColor Red From 6ab44e4f257ea5645ddaa54cc670c7c1ea092299 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 10 Sep 2023 12:02:00 +0200 Subject: [PATCH 4/6] Microsoft.UI.XAML.2.7 not needed,removed --- Winget-AutoUpdate-Install.ps1 | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index b4ad390..5623937 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -196,25 +196,7 @@ function Install-WinGet { Write-Host "-> Winget is not installed:" - #Downloading and Installing Dependencies in SYSTEM context - if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) { - Write-Host "-> Downloading Microsoft.UI.Xaml.2.7..." - $UiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0" - $UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip" - Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip - Expand-Archive -Path $UiXamlZip -DestinationPath "$WingetUpdatePath\extracted" -Force - try { - Write-Host "-> Installing Microsoft.UI.Xaml.2.7..." - Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null - Write-host "Microsoft.UI.Xaml.2.7 installed successfully" -ForegroundColor Green - } - catch { - Write-Host "Failed to intall Wicrosoft.UI.Xaml.2.7..." -ForegroundColor Red - } - Remove-Item -Path $UiXamlZip -Force - Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse - } - + #Downloading and Installing Microsoft.VCLibs.140.00.UWPDesktop in SYSTEM context if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) { Write-Host "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..." $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" From 2b433d2bb5a7faa644fddf57f2d7f2434e21f05f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 10 Sep 2023 12:34:14 +0200 Subject: [PATCH 5/6] Create $WingetUpdatePath if not exist --- Winget-AutoUpdate-Install.ps1 | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 5623937..f2f3a32 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -196,7 +196,30 @@ function Install-WinGet { Write-Host "-> Winget is not installed:" - #Downloading and Installing Microsoft.VCLibs.140.00.UWPDesktop in SYSTEM context + #Check if $WingetUpdatePath exist + if (!(Test-Path $WingetUpdatePath)) { + New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null + } + + #Downloading and Installing Dependencies in SYSTEM context + if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) { + Write-Host "-> Downloading Microsoft.UI.Xaml.2.7..." + $UiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0" + $UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip" + Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip + Expand-Archive -Path $UiXamlZip -DestinationPath "$WingetUpdatePath\extracted" -Force + try { + Write-Host "-> Installing Microsoft.UI.Xaml.2.7..." + Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null + Write-host "Microsoft.UI.Xaml.2.7 installed successfully" -ForegroundColor Green + } + catch { + Write-Host "Failed to intall Wicrosoft.UI.Xaml.2.7..." -ForegroundColor Red + } + Remove-Item -Path $UiXamlZip -Force + Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse + } + if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) { Write-Host "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..." $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" From 1147a2f0fdba43e11ca8e65fce70ed822bc4a18d Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 10 Sep 2023 15:05:25 +0200 Subject: [PATCH 6/6] Winget v1.5.2201 --- Winget-AutoUpdate-Install.ps1 | 6 +++--- Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index f2f3a32..6ab9df9 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -186,8 +186,8 @@ function Install-WinGet { #Check Package Install $TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } - #Current: v1.5.1881 = 1.20.1881.0 = 2023.707.2257.0 - If ([Version]$TestWinGet.Version -ge "2023.707.2257.0") { + #Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0 + If ([Version]$TestWinGet.Version -ge "2023.808.2243.0") { Write-Host "Winget is Installed" -ForegroundColor Green @@ -238,7 +238,7 @@ function Install-WinGet { #Download WinGet MSIXBundle Write-Host "-> Downloading Winget MSIXBundle for App Installer..." - $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" + $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index cc7bb40..2637718 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -54,8 +54,8 @@ function Invoke-PostUpdateActions { Write-ToLog "-> Checking if Winget is installed/up to date" "yellow" $TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } - #Current: v1.5.1881 = 1.20.1881.0 = 2023.707.2257.0 - If ([Version]$TestWinGet.Version -ge "2023.707.2257.0") { + #Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0 + If ([Version]$TestWinGet.Version -ge "2023.808.2243.0") { Write-ToLog "-> WinGet is Installed/up to date" "green" @@ -64,7 +64,7 @@ function Invoke-PostUpdateActions { #Download WinGet MSIXBundle Write-ToLog "-> Not installed/up to date. Downloading WinGet..." - $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" + $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")