Skip to content

Commit aa6f0ca

Browse files
committed
WAU script hardening
1 parent 17fcdc6 commit aa6f0ca

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

Sources/Winget-AutoUpdate/WAU-Installer-GUI.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Add-Type -AssemblyName PresentationFramework
381381
Start-PopUp "Starting..."
382382

383383
#Set config
384-
$null = cmd /c ''
384+
$null = & "$env:WINDIR\System32\cmd.exe" /c ""
385385
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
386386
$Script:ProgressPreference = "SilentlyContinue"
387387
$Script:ErrorActionPreference = "SilentlyContinue"

Sources/Winget-AutoUpdate/Winget-Upgrade.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Get-ChildItem -Path "$($Script:WorkingDir)\functions" -File -Filter "*.ps1" -Dep
99
<# MAIN #>
1010

1111
# Config console output encoding
12-
$null = cmd /c '';
12+
$null = & "$env:WINDIR\System32\cmd.exe" /c ""
1313
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
1414
$Script:ProgressPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue;
1515

Sources/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
function Get-WingetOutdatedApps {
44

5-
Param(
6-
[Parameter(Position=0,Mandatory=$True,HelpMessage="You MUST supply value for winget repo, we need it")]
7-
[ValidateNotNullorEmpty()]
8-
[string]$src
9-
)
5+
Param(
6+
[Parameter(Position = 0, Mandatory = $True, HelpMessage = "You MUST supply value for winget repo, we need it")]
7+
[ValidateNotNullorEmpty()]
8+
[string]$src
9+
)
1010
class Software {
1111
[string]$Name
1212
[string]$Id
@@ -15,7 +15,13 @@ Param(
1515
}
1616

1717
#Get list of available upgrades on winget format
18-
$upgradeResult = & $Winget upgrade --source $src | Where-Object { $_ -notlike " *" } | Out-String
18+
try {
19+
$upgradeResult = & $Winget upgrade --source $src | Where-Object { $_ -notlike " *" } | Out-String
20+
}
21+
catch {
22+
Write-ToLog "Error while recieving winget upgrade list: $_" "Red"
23+
$upgradeResult = $null
24+
}
1925

2026
#Start Conversion of winget format to an array. Check if "-----" exists (Winget Error Handling)
2127
if (!($upgradeResult -match "-----")) {

Sources/Winget-AutoUpdate/functions/Test-Network.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ function Test-Network {
3232
Write-ToLog "Connected !" "Green"
3333

3434
#Check for metered connection
35-
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
36-
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
35+
try {
36+
Add-Type -AssemblyName 'Windows.Networking, ContentType=WindowsRuntime' -ErrorAction Stop
37+
#[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
38+
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
39+
}
40+
catch {
41+
Write-ToLog "Could not evaluate metered connection status - skipping check." "Gray"
42+
return $true
43+
}
3744

3845
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")) {
3946

0 commit comments

Comments
 (0)