Optimized if run as System...

pull/257/head
KnifMelti 2022-12-28 17:28:22 +01:00
parent ba6ed977b8
commit e2c446a2be
1 changed files with 15 additions and 22 deletions

View File

@ -14,18 +14,12 @@ $Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsS
#Run log initialisation function #Run log initialisation function
Start-Init Start-Init
#Log running context
if ($IsSystem) {
Write-Log "Running in System context"
}
else {
Write-Log "Running in User context"
}
#Get WAU Configurations #Get WAU Configurations
$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
#Log running context and more...
if ($IsSystem) { if ($IsSystem) {
Write-Log "Running in System context"
#Get WAU Policies and set the Configurations Registry Accordingly #Get WAU Policies and set the Configurations Registry Accordingly
$WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue
if ($WAUPolicies) { if ($WAUPolicies) {
@ -89,18 +83,17 @@ if ($IsSystem) {
} }
} }
} }
} #Run post update actions if necessary if run as System
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) {
#Run post update actions if necessary Invoke-PostUpdateActions
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { }
Invoke-PostUpdateActions #Run Scope Machine funtion if run as System
}
#Run Scope Machine funtion if run as system
if ($IsSystem) {
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json" $SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
Add-ScopeMachine $SettingsPath Add-ScopeMachine $SettingsPath
} }
else {
Write-Log "Running in User context"
}
#Get Notif Locale function #Get Notif Locale function
$LocaleDisplayName = Get-NotifLocale $LocaleDisplayName = Get-NotifLocale
@ -116,9 +109,9 @@ if (Test-Network) {
$WAUCurrentVersion = $WAUConfig.DisplayVersion $WAUCurrentVersion = $WAUConfig.DisplayVersion
Write-Log "WAU current version: $WAUCurrentVersion" Write-Log "WAU current version: $WAUCurrentVersion"
if ($IsSystem) { if ($IsSystem) {
#Check if WAU update feature is enabled or not #Check if WAU update feature is enabled or not if run as System
$WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate $WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate
#If yes then check WAU update if System #If yes then check WAU update if run as System
if ($WAUDisableAutoUpdate -eq 1) { if ($WAUDisableAutoUpdate -eq 1) {
Write-Log "WAU AutoUpdate is Disabled." "Grey" Write-Log "WAU AutoUpdate is Disabled." "Grey"
} }
@ -137,12 +130,12 @@ if (Test-Network) {
} }
} }
#Delete previous list_/winget_error (if they exist) if System #Delete previous list_/winget_error (if they exist) if run as System
if (Test-Path "$WorkingDir\logs\error.txt") { if (Test-Path "$WorkingDir\logs\error.txt") {
Remove-Item "$WorkingDir\logs\error.txt" -Force Remove-Item "$WorkingDir\logs\error.txt" -Force
} }
#Get External ListPath if System #Get External ListPath if run as System
if ($WAUConfig.WAU_ListPath) { if ($WAUConfig.WAU_ListPath) {
Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))" Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))"
$NewList = Test-ListPath $WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/") $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\") $NewList = Test-ListPath $WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/") $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\")
@ -161,7 +154,7 @@ if (Test-Network) {
} }
} }
#Get External ModsPath if System #Get External ModsPath if run as System
if ($WAUConfig.WAU_ModsPath) { if ($WAUConfig.WAU_ModsPath) {
Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))" Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))"
$NewMods, $DeletedMods = Test-ModsPath $WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/") $WAUConfig.InstallLocation.TrimEnd(" ", "\") $NewMods, $DeletedMods = Test-ModsPath $WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/") $WAUConfig.InstallLocation.TrimEnd(" ", "\")