add metered connection detection and option

pull/115/head
romanitho 2022-06-29 17:32:03 +02:00
parent 506731c2f6
commit 82598adf05
2 changed files with 34 additions and 1 deletions

View File

@ -34,6 +34,9 @@ Set WAU to run at user logon.
.PARAMETER UpdatesInterval
Specify the update frequency: Daily (Default), Weekly, Biweekly or Monthly.
.PARAMETER RunOnMetered
Run WAU on metered connection. Default No.
.EXAMPLE
.\winget-install-and-update.ps1 -Silent -DoNotUpdate
@ -251,6 +254,9 @@ function Install-WingetAutoUpdate {
if ($UseWhiteList) {
New-ItemProperty $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force | Out-Null
}
if (!$RunOnMetered) {
New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null
}
Write-host "WAU Installation succeeded!" -ForegroundColor Green
Start-sleep 1

View File

@ -14,9 +14,36 @@ function Test-Network {
if ($TestNetwork) {
Write-Log "Connected !" "Green"
#Check for metered connection
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")){
Write-Log "Metered connection detected." "Yellow"
if ($WAUConfig.WAU_DoNotRunOnMetered -eq 1) {
Write-Log "WAU is configured to bypass update checking on metered connection"
return $false
}
else{
Write-Log "WAU is configured to force update checking on metered connection"
return $true
}
}
else{
return $true
}
}
else {
Start-Sleep 10