Final touches
parent
e42a8cedaa
commit
8835de9f90
|
@ -311,6 +311,18 @@ if (Test-Network) {
|
||||||
#Run WAU in user context if feature is activated
|
#Run WAU in user context if feature is activated
|
||||||
if ($WAUConfig.WAU_UserContext -eq 1) {
|
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
|
#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)
|
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
|
||||||
If ($explorerprocesses.Count -eq 0) {
|
If ($explorerprocesses.Count -eq 0) {
|
||||||
|
|
|
@ -186,26 +186,18 @@ function Invoke-PostUpdateActions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Create User context task if not existing and manage its activation
|
#Activate WAU in user context if previously configured (as "Winget-AutoUpdate-UserContext" at root)
|
||||||
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
|
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath '\' -ErrorAction SilentlyContinue
|
||||||
if (!$UserContextTask) {
|
if ($UserContextTask) {
|
||||||
#Create the scheduled task in User context
|
#Remove Winget-AutoUpdate-UserContext at root.
|
||||||
$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`""
|
Unregister-ScheduledTask $UserContextTask -Confirm:$False
|
||||||
$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
|
|
||||||
|
|
||||||
#If scheduled task didn't exist, user context was not activated. Set it in registry.
|
#Set it in registry as activated.
|
||||||
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)) {
|
|
||||||
New-ItemProperty $regPath -Name WAU_UserContext -Value 1 -PropertyType DWord -Force | Out-Null
|
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 ###
|
### End of post update actions ###
|
||||||
|
|
||||||
#Reset WAU_UpdatePostActions Value
|
#Reset WAU_UpdatePostActions Value
|
||||||
|
|
Loading…
Reference in New Issue