Starting a bit of cleaning

pull/458/head
romanitho 2023-10-30 18:42:58 +01:00
parent be98907306
commit f3ed009fcf
5 changed files with 84 additions and 118 deletions

View File

@ -162,7 +162,7 @@ Setting it to 1 keeps the original one and just let it grow.
Specify the size of the log file in bytes before rotating.<br> Specify the size of the log file in bytes before rotating.<br>
Default is 1048576 = 1 MB (ca. 7500 lines) Default is 1048576 = 1 MB (ca. 7500 lines)
**-WingetUpdatePath**<br> **-WAUinstallPath**<br>
Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default). Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default).
**-Uninstall**<br> **-Uninstall**<br>

View File

@ -16,7 +16,7 @@ Specify number of allowed log files (Default is 3 of 0-99: Setting MaxLogFiles t
.PARAMETER MaxLogSize .PARAMETER MaxLogSize
Specify the size of the log file in bytes before rotating. (Default is 1048576 = 1 MB) Specify the size of the log file in bytes before rotating. (Default is 1048576 = 1 MB)
.PARAMETER WingetUpdatePath .PARAMETER WAUinstallPath
Specify Winget-AutoUpdate installation localtion. Default: C:\ProgramData\Winget-AutoUpdate\ Specify Winget-AutoUpdate installation localtion. Default: C:\ProgramData\Winget-AutoUpdate\
.PARAMETER DoNotUpdate .PARAMETER DoNotUpdate
@ -93,7 +93,7 @@ Configure WAU to bypass the Black/White list when run in user context. Applicati
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false, [Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false,
[Parameter(Mandatory = $False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", [Parameter(Mandatory = $False)] [Alias('Path', 'WingetUpdatePath')] [String] $WAUinstallPath = "$env:ProgramData\Winget-AutoUpdate",
[Parameter(Mandatory = $False)] [Alias('List')] [String] $ListPath, [Parameter(Mandatory = $False)] [Alias('List')] [String] $ListPath,
[Parameter(Mandatory = $False)] [Alias('Mods')] [String] $ModsPath, [Parameter(Mandatory = $False)] [Alias('Mods')] [String] $ModsPath,
[Parameter(Mandatory = $False)] [Alias('AzureBlobURL')] [String] $AzureBlobSASURL, [Parameter(Mandatory = $False)] [Alias('AzureBlobURL')] [String] $AzureBlobSASURL,
@ -139,7 +139,7 @@ function Install-Prerequisites {
if (!($path)) { if (!($path)) {
#If -silent option, force installation #If -silent option, force installation
if ($Silent) { if ($Silent) {
$InstallApp = 1 $InstallApp = $True
} }
else { else {
#Ask for installation #Ask for installation
@ -148,28 +148,30 @@ function Install-Prerequisites {
$MsgBoxTimeOut = 60 $MsgBoxTimeOut = 60
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent, $MsgBoxTimeOut, $MsgBoxTitle, 4 + 32) $MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent, $MsgBoxTimeOut, $MsgBoxTitle, 4 + 32)
if ($MsgBoxReturn -ne 7) { if ($MsgBoxReturn -ne 7) {
$InstallApp = 1 $InstallApp = $True
}
else {
$InstallApp = 0
} }
} }
#Install if approved #Install if approved
if ($InstallApp -eq 1) { if ($InstallApp) {
try { try {
if ((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*") { #Get proc architecture
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
$OSArch = "arm64"
}
elseif ($env:PROCESSOR_ARCHITECTURE -like "*64*") {
$OSArch = "x64" $OSArch = "x64"
} }
else { else {
$OSArch = "x86" $OSArch = "x86"
} }
Write-ToLog "-> Downloading VC_redist.$OSArch.exe..."
$SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe" $SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
$Installer = $WingetUpdatePath + "\VC_redist.$OSArch.exe" $Installer = $WAUinstallPath + "\VC_redist.$OSArch.exe"
$ProgressPreference = 'SilentlyContinue' Write-ToLog "-> Downloading VC_redist.$OSArch.exe..."
Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force) Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force)
Write-ToLog "-> Installing VC_redist.$OSArch.exe..." Write-ToLog "-> Installing VC_redist.$OSArch.exe..."
Start-Process -FilePath $Installer -Args "/quiet /norestart" -Wait Start-Process -FilePath $Installer -Args "/passive /norestart" -Wait
Start-Sleep 1
Remove-Item $Installer -ErrorAction Ignore Remove-Item $Installer -ErrorAction Ignore
Write-ToLog "-> MS Visual C++ 2015-2022 installed successfully`n" "Green" Write-ToLog "-> MS Visual C++ 2015-2022 installed successfully`n" "Green"
} }
@ -189,59 +191,32 @@ function Install-Prerequisites {
function Install-WinGet { function Install-WinGet {
Write-ToLog "Checking if WinGet is installed/up to date" "Yellow" Write-ToLog "Checking if WinGet is installed/up to date." "Yellow"
#Check available WinGet version, if fail set version to the latest version as of 2023-10-08 #Check available WinGet version
$WinGetAvailableVersion = Get-WinGetAvailableVersion $WinGetAvailableVersion = Get-WinGetAvailableVersion
if (!$WinGetAvailableVersion) {
$WinGetAvailableVersion = "1.6.2771" try {
#Get Admin Context Winget Location
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
#If multiple versions, pick most recent one
$WingetCmd = $WingetInfo[-1].FileName
#Get current Winget Version
$WingetInstalledVersion = ((& $WingetCmd -v).Replace("-preview", "")).Replace("v", "")
}
catch {
Write-ToLog "-> WinGet is not installed" "Red"
} }
#Check if WinGet is installed, if not set version to dummy... #Check if the current available WinGet is newer than the installed
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($WinGetAvailableVersion -gt $WinGetInstalledVersion) {
if (!$ResolveWingetPath) {
$WinGetInstalledVersion = "0.0.0000"
}
else {
#If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path
$WinGetInstalledVersion = & $WingetPath --version
$WinGetInstalledVersion = $WinGetInstalledVersion.Replace("v", "")
}
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) {
Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "Red"
#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' -AllUsers)) {
Write-ToLog "-> 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-ToLog "-> 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-ToLog "-> Microsoft.UI.Xaml.2.7 installed successfully" "Green"
}
catch {
Write-ToLog "-> Failed to intall Wicrosoft.UI.Xaml.2.7..." "Red"
}
Remove-Item -Path $UiXamlZip -Force
Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse
}
#Check if Microsoft.VCLibs.140.00.UWPDesktop is installed
if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop' -AllUsers)) { if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop' -AllUsers)) {
Write-ToLog "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..." Write-ToLog "Microsoft.VCLibs.140.00.UWPDesktop is not installed" "Red"
$VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
$VCLibsFile = "$WingetUpdatePath\Microsoft.VCLibs.x64.14.00.Desktop.appx" $VCLibsFile = "$env:TEMP\Microsoft.VCLibs.x64.14.00.Desktop.appx"
Write-ToLog "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..."
Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile
try { try {
Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..." Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..."
@ -254,13 +229,10 @@ function Install-WinGet {
Remove-Item -Path $VCLibsFile -Force Remove-Item -Path $VCLibsFile -Force
} }
Update-WinGet $WinGetAvailableVersion $WingetUpdatePath #Install/Update Winget
Update-WinGet $WinGetAvailableVersion
} }
elseif ($WinGetAvailableVersion -match "-pre") {
Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release." "Yellow"
Update-StoreApps
}
else { else {
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion`n" "Green" Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion`n" "Green"
} }
@ -272,49 +244,49 @@ function Install-WingetAutoUpdate {
try { try {
#Copy files to location (and clean old install) #Copy files to location (and clean old install)
if (!(Test-Path $WingetUpdatePath)) { if (!(Test-Path $WAUinstallPath)) {
New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null New-Item -ItemType Directory -Force -Path $WAUinstallPath | Out-Null
} }
else { else {
if (!$NoClean) { if (!$NoClean) {
Remove-Item -Path "$WingetUpdatePath\*" -Exclude *.log -Recurse -Force Remove-Item -Path "$WAUinstallPath\*" -Exclude *.log -Recurse -Force
} }
else { else {
#Keep critical files #Keep critical files
Get-ChildItem -Path $WingetUpdatePath -Exclude *.txt, mods, logs | Remove-Item -Recurse -Force Get-ChildItem -Path $WAUinstallPath -Exclude *.txt, mods, logs | Remove-Item -Recurse -Force
} }
} }
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue
#White List or Black List apps #White List or Black List apps
if ($UseWhiteList) { if ($UseWhiteList) {
if (!$NoClean) { if (!$NoClean) {
if ((Test-Path "$PSScriptRoot\included_apps.txt")) { if ((Test-Path "$PSScriptRoot\included_apps.txt")) {
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue
} }
else { else {
if (!$ListPath) { if (!$ListPath) {
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null New-Item -Path $WAUinstallPath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null
} }
} }
} }
elseif (!(Test-Path "$WingetUpdatePath\included_apps.txt")) { elseif (!(Test-Path "$WAUinstallPath\included_apps.txt")) {
if ((Test-Path "$PSScriptRoot\included_apps.txt")) { if ((Test-Path "$PSScriptRoot\included_apps.txt")) {
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue
} }
else { else {
if (!$ListPath) { if (!$ListPath) {
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null New-Item -Path $WAUinstallPath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null
} }
} }
} }
} }
else { else {
if (!$NoClean) { if (!$NoClean) {
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue
} }
elseif (!(Test-Path "$WingetUpdatePath\excluded_apps.txt")) { elseif (!(Test-Path "$WAUinstallPath\excluded_apps.txt")) {
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue
} }
} }
@ -328,7 +300,7 @@ function Install-WingetAutoUpdate {
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
# Settings for the scheduled task for Updates (System) # Settings for the scheduled task for Updates (System)
$taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`"" $taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WAUinstallPath)\winget-upgrade.ps1`""
$taskTriggers = @() $taskTriggers = @()
if ($UpdatesAtLogon) { if ($UpdatesAtLogon) {
$tasktriggers += New-ScheduledTaskTrigger -AtLogOn $tasktriggers += New-ScheduledTaskTrigger -AtLogOn
@ -360,7 +332,7 @@ function Install-WingetAutoUpdate {
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -TaskPath 'WAU' -InputObject $task -Force | Out-Null Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
# Settings for the scheduled task in User context # Settings for the scheduled task in User context
$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`"" $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WAUinstallPath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUinstallPath)\winget-upgrade.ps1`"`""
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11 $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
# Set up the task for user apps # Set up the task for user apps
@ -368,7 +340,7 @@ function Install-WingetAutoUpdate {
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath 'WAU' -InputObject $task -Force | Out-Null Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
# Settings for the scheduled task for Notifications # Settings for the scheduled task for Notifications
$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`"" $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WAUinstallPath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUinstallPath)\winget-notify.ps1`"`""
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11 $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00 $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
# Set up the task, and register it # Set up the task, and register it
@ -376,7 +348,7 @@ function Install-WingetAutoUpdate {
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -TaskPath 'WAU' -InputObject $task -Force | Out-Null Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
# Settings for the GPO scheduled task # Settings for the GPO scheduled task
$taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\WAU-Policies.ps1`"" $taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WAUinstallPath)\WAU-Policies.ps1`""
$tasktrigger = New-ScheduledTaskTrigger -Daily -At 6am $tasktrigger = New-ScheduledTaskTrigger -Daily -At 6am
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest $taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00 $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
@ -398,9 +370,9 @@ function Install-WingetAutoUpdate {
New-ItemProperty $regPath -Name DisplayName -Value "Winget-AutoUpdate (WAU)" -Force | Out-Null New-ItemProperty $regPath -Name DisplayName -Value "Winget-AutoUpdate (WAU)" -Force | Out-Null
New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force | Out-Null New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force | Out-Null
New-ItemProperty $regPath -Name DisplayVersion -Value $WAUVersion -Force | Out-Null New-ItemProperty $regPath -Name DisplayVersion -Value $WAUVersion -Force | Out-Null
New-ItemProperty $regPath -Name InstallLocation -Value $WingetUpdatePath -Force | Out-Null New-ItemProperty $regPath -Name InstallLocation -Value $WAUinstallPath -Force | Out-Null
New-ItemProperty $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null New-ItemProperty $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WAUinstallPath\WAU-Uninstall.ps1`"" -Force | Out-Null
New-ItemProperty $regPath -Name QuietUninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null New-ItemProperty $regPath -Name QuietUninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WAUinstallPath\WAU-Uninstall.ps1`"" -Force | Out-Null
New-ItemProperty $regPath -Name NoModify -Value 1 -Force | Out-Null New-ItemProperty $regPath -Name NoModify -Value 1 -Force | Out-Null
New-ItemProperty $regPath -Name NoRepair -Value 1 -Force | Out-Null New-ItemProperty $regPath -Name NoRepair -Value 1 -Force | Out-Null
New-ItemProperty $regPath -Name Publisher -Value "Romanitho" -Force | Out-Null New-ItemProperty $regPath -Name Publisher -Value "Romanitho" -Force | Out-Null
@ -453,7 +425,7 @@ function Install-WingetAutoUpdate {
#Security check #Security check
Write-ToLog "Checking Mods Directory:" "Yellow" Write-ToLog "Checking Mods Directory:" "Yellow"
$Protected = Invoke-ModsProtect "$WingetUpdatePath\mods" $Protected = Invoke-ModsProtect "$WAUinstallPath\mods"
if ($Protected -eq $True) { if ($Protected -eq $True) {
Write-ToLog "-> The mods directory is now secured!`n" "Green" Write-ToLog "-> The mods directory is now secured!`n" "Green"
} }
@ -469,13 +441,13 @@ function Install-WingetAutoUpdate {
if (!(Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) { if (!(Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) {
New-Item -ItemType Directory -Force -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" | Out-Null New-Item -ItemType Directory -Force -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" | Out-Null
} }
Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Check for updated Apps.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..." Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Check for updated Apps.lnk" "`"$($WAUinstallPath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUinstallPath)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Open logs.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" "Open existing WAU logs..." Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Open logs.lnk" "`"$($WAUinstallPath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUinstallPath)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" "Open existing WAU logs..."
Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Web Help.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..." Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Web Help.lnk" "`"$($WAUinstallPath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUinstallPath)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..."
} }
if ($DesktopShortcut) { if ($DesktopShortcut) {
Add-Shortcut "wscript.exe" "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..." Add-Shortcut "wscript.exe" "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" "`"$($WAUinstallPath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUinstallPath)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
} }
Write-ToLog "WAU Installation succeeded!" "Green" Write-ToLog "WAU Installation succeeded!" "Green"
@ -548,7 +520,7 @@ function Start-WingetAutoUpdate {
if (!($DoNotUpdate)) { if (!($DoNotUpdate)) {
#If -Silent, run Winget-AutoUpdate now #If -Silent, run Winget-AutoUpdate now
if ($Silent) { if ($Silent) {
$RunWinget = 1 $RunWinget = $True
} }
#Ask for WingetAutoUpdate #Ask for WingetAutoUpdate
else { else {
@ -557,13 +529,10 @@ function Start-WingetAutoUpdate {
$MsgBoxTimeOut = 60 $MsgBoxTimeOut = 60
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent, $MsgBoxTimeOut, $MsgBoxTitle, 4 + 32) $MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent, $MsgBoxTimeOut, $MsgBoxTitle, 4 + 32)
if ($MsgBoxReturn -ne 7) { if ($MsgBoxReturn -ne 7) {
$RunWinget = 1 $RunWinget = $True
}
else {
$RunWinget = 0
} }
} }
if ($RunWinget -eq 1) { if ($RunWinget) {
try { try {
Write-ToLog "Running Winget-AutoUpdate..." "Yellow" Write-ToLog "Running Winget-AutoUpdate..." "Yellow"
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
@ -605,7 +574,7 @@ $null = cmd /c '' #Tip for ISE
$Script:ProgressPreference = 'SilentlyContinue' $Script:ProgressPreference = 'SilentlyContinue'
#Set install log file #Set install log file
$Script:LogFile = "$WingetUpdatePath\logs\WAU-Installer.log" $Script:LogFile = "$WAUinstallPath\logs\WAU-Installer.log"
Write-Host "`n " Write-Host "`n "
Write-Host "`t 888 888 d8888 888 888" -ForegroundColor Magenta Write-Host "`t 888 888 d8888 888 888" -ForegroundColor Magenta
@ -621,7 +590,7 @@ Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n " -Foregroun
Write-Host "`t________________________________________________________`n `n " Write-Host "`t________________________________________________________`n `n "
if (!$Uninstall) { if (!$Uninstall) {
Write-ToLog "Installing WAU to $WingetUpdatePath\" Write-ToLog "Installing WAU to $WAUinstallPath\"
Install-Prerequisites Install-Prerequisites
Install-WinGet Install-WinGet
Install-WingetAutoUpdate Install-WingetAutoUpdate
@ -631,8 +600,8 @@ else {
Uninstall-WingetAutoUpdate Uninstall-WingetAutoUpdate
} }
if (Test-Path "$WingetUpdatePath\Version.txt") { if (Test-Path "$WAUinstallPath\Version.txt") {
Remove-Item "$WingetUpdatePath\Version.txt" -Force Remove-Item "$WAUinstallPath\Version.txt" -Force
} }
Write-ToLog "End of process." "Cyan" Write-ToLog "End of process." "Cyan"

View File

@ -9,7 +9,8 @@ Function Get-WinGetAvailableVersion {
return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
} }
catch { catch {
return $false #if fail set version to the latest version as of 2023-10-08
return "1.6.2771"
} }
} }

View File

@ -19,11 +19,8 @@ function Invoke-PostUpdateActions {
Write-ToLog "-> Checking if WinGet is installed/up to date" "yellow" Write-ToLog "-> Checking if WinGet is installed/up to date" "yellow"
#Check available WinGet version, if fail set version to the latest version as of 2023-10-08 #Check available WinGet version
$WinGetAvailableVersion = Get-WinGetAvailableVersion $WinGetAvailableVersion = Get-WinGetAvailableVersion
if (!$WinGetAvailableVersion) {
$WinGetAvailableVersion = "1.6.2771"
}
#Check installed WinGet version #Check installed WinGet version
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
@ -37,7 +34,7 @@ function Invoke-PostUpdateActions {
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) { if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) {
Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "red" Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "red"
Update-WinGet $WinGetAvailableVersion $($WAUConfig.InstallLocation) Update-WinGet $WinGetAvailableVersion
} }
elseif ($WinGetAvailableVersion -match "-pre") { elseif ($WinGetAvailableVersion -match "-pre") {
Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow" Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow"

View File

@ -1,6 +1,6 @@
#Function to download and update WinGet #Function to download and update WinGet
Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath) { Function Update-WinGet ($WinGetAvailableVersion) {
$download_string = "-> Downloading WinGet MSIXBundle for App Installer..." $download_string = "-> Downloading WinGet MSIXBundle for App Installer..."
$install_string = "-> Installing WinGet MSIXBundle for App Installer..." $install_string = "-> Installing WinGet MSIXBundle for App Installer..."
@ -11,23 +11,22 @@ Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath) {
#Download WinGet MSIXBundle #Download WinGet MSIXBundle
Write-ToLog $download_string Write-ToLog $download_string
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$WebClient = New-Object System.Net.WebClient $WingetInstaller = "$env:TEMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$WebClient.DownloadFile($WinGetURL, "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") Invoke-RestMethod -Uri $WinGetURL -OutFile $WingetInstaller
#Install WinGet MSIXBundle in SYSTEM context #Install WinGet MSIXBundle in SYSTEM context
try { try {
Write-ToLog $install_string Write-ToLog $install_string
Add-AppxProvisionedPackage -Online -PackagePath "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath $WingetInstaller -SkipLicense | Out-Null
Write-ToLog $success_string "green" Write-ToLog $success_string "green"
#Reset WinGet Sources #Reset WinGet Sources
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } $WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
if ($ResolveWingetPath) { #If multiple versions, pick most recent one
Write-ToLog $reset_string "green" $WingetCmd = $WingetInfo[-1].FileName
#If multiple version, pick last one & $WingetCmd source reset --force
$WingetPath = $ResolveWingetPath[-1].Path Write-ToLog $reset_string "green"
& $WingetPath source reset --force
}
} }
catch { catch {
Write-ToLog $fail_string "red" Write-ToLog $fail_string "red"
@ -35,5 +34,5 @@ Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath) {
} }
#Remove WinGet MSIXBundle #Remove WinGet MSIXBundle
Remove-Item -Path "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue Remove-Item -Path $WingetInstaller -Force -ErrorAction SilentlyContinue
} }