Skip to content

Commit

Permalink
clean a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanitho authored Aug 17, 2024
1 parent 4977817 commit 51f5d40
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions Sources/Winget-AutoUpdate/Winget-Upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ if (Test-Network) {

if ($Winget) {

#Log Winget installed version
$WingetVer = & $Winget --version
Write-ToLog "Winget Version: $WingetVer"

#Get Current Version
$WAUCurrentVersion = $WAUConfig.ProductVersion
Write-ToLog "WAU current version: $WAUCurrentVersion"
Expand Down Expand Up @@ -369,27 +365,23 @@ if (Test-Network) {
}

#Check if user context is activated during system run
if ($IsSystem) {
if ($IsSystem -and ($WAUConfig.WAU_UserContext -eq 1)) {

#Run WAU in user context if feature is activated
if ($WAUConfig.WAU_UserContext -eq 1) {
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue

$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue

$explorerprocesses = @(Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
If ($explorerprocesses.Count -eq 0) {
Write-ToLog "No explorer process found / Nobody interactively logged on..."
}
Else {
#Get Winget system apps to excape them befor running user context
Write-ToLog "User logged on, get a list of installed Winget apps in System context..."
Get-WingetSystemApps

#Run user context scheduled task
Write-ToLog "Starting WAU in User context..."
$null = $UserContextTask | Start-ScheduledTask -ErrorAction SilentlyContinue
Exit 0
}
$explorerprocesses = @(Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
If ($explorerprocesses.Count -eq 0) {
Write-ToLog "No explorer process found / Nobody interactively logged on..."
}
Else {
#Get Winget system apps to excape them befor running user context
Write-ToLog "User logged on, get a list of installed Winget apps in System context..."
Get-WingetSystemApps

#Run user context scheduled task
Write-ToLog "Starting WAU in User context..."
$null = $UserContextTask | Start-ScheduledTask -ErrorAction SilentlyContinue
Exit 0
}
}
}
Expand Down

0 comments on commit 51f5d40

Please sign in to comment.