Final touches
parent
a1152457f1
commit
7531aa399e
|
@ -311,6 +311,18 @@ if (Test-Network) {
|
|||
#Run WAU in user context if feature is activated
|
||||
if ($WAUConfig.WAU_UserContext -eq 1) {
|
||||
|
||||
#Create User context task if not existing
|
||||
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
|
||||
if (!$UserContextTask) {
|
||||
#Create 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`"`""
|
||||
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
|
||||
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
|
||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
|
||||
Write-ToLog "-> User Context task created."
|
||||
}
|
||||
|
||||
#User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status
|
||||
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
|
||||
If ($explorerprocesses.Count -eq 0) {
|
||||
|
|
|
@ -186,26 +186,18 @@ function Invoke-PostUpdateActions {
|
|||
}
|
||||
}
|
||||
|
||||
#Create User context task if not existing and manage its activation
|
||||
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
|
||||
if (!$UserContextTask) {
|
||||
#Create 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`"`""
|
||||
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
|
||||
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
|
||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
|
||||
#Activate WAU in user context if previously configured (as "Winget-AutoUpdate-UserContext" at root)
|
||||
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath '\' -ErrorAction SilentlyContinue
|
||||
if ($UserContextTask) {
|
||||
#Remove Winget-AutoUpdate-UserContext at root.
|
||||
Unregister-ScheduledTask $UserContextTask -Confirm:$False
|
||||
|
||||
#If scheduled task didn't exist, user context was not activated. Set it in registry.
|
||||
New-ItemProperty $regPath -Name WAU_UserContext -Value 0 -PropertyType DWord -Force | Out-Null
|
||||
Write-ToLog "-> User Context task created and set to 'disabled' in registry."
|
||||
}
|
||||
#If scheduled task exists but no WAU_UserContext setting, user context was activated. Set it in registry.
|
||||
elseif (!($WAUConfig.WAU_UserContext)) {
|
||||
#Set it in registry as activated.
|
||||
New-ItemProperty $regPath -Name WAU_UserContext -Value 1 -PropertyType DWord -Force | Out-Null
|
||||
Write-ToLog "-> User Context task existes and set to 'enabled' in registry."
|
||||
Write-ToLog "-> Old User Context task deleted and set to 'enabled' in registry."
|
||||
}
|
||||
|
||||
|
||||
### End of post update actions ###
|
||||
|
||||
#Reset WAU_UpdatePostActions Value
|
||||
|
|
Loading…
Reference in New Issue