UserContext and fixes to settings

pull/257/head
KnifMelti 2022-12-31 00:59:46 +01:00
parent 57733fbcf6
commit ab215d8615
3 changed files with 33 additions and 0 deletions

View File

@ -288,6 +288,16 @@
</item>
</enum>
</elements>
</policy>
<policy name="UserContext_Enable" class="Machine" displayName="$(string.UserContext_Name)" explainText="$(string.UserContext_Explain)" key="Software\Policies\Romanitho\Winget-AutoUpdate" valueName="WAU_UserContext">
<parentCategory ref="WAU"/>
<supportedOn ref="WAU:SUPPORTED_WAU_1_15_3"/>
<enabledValue>
<decimal value="1" />
</enabledValue>
<disabledValue>
<decimal value="0" />
</disabledValue>
</policy>
</policies>
</policyDefinitions>

View File

@ -97,6 +97,10 @@ If this policy is not configured or disabled, Updates at Time: (06:00 AM).</stri
<string id="UpdatesAtTime22">22:00</string>
<string id="UpdatesAtTime23">23:00</string>
<string id="UpdatesAtTime24">24:00</string>
<string id="UserContext_Name">User context execution</string>
<string id="UserContext_Explain">This policy setting specifies whether to enable User context execution or not .
If this policy is disabled or not configured, the default is No.</string>
</stringTable>
<presentationTable>
<presentation id="ListPath">

View File

@ -237,6 +237,25 @@ Function Get-Policies {
$ChangedSettings++
}
if ($null -ne $($WAUPolicies.WAU_UserContext) -and ($($WAUPolicies.WAU_UserContext) -ne $($WAUConfig.WAU_UserContext))) {
#Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
New-ItemProperty $regPath -Name WAU_UserContext -Value $($WAUPolicies.WAU_UserContext) -PropertyType DWord -Force | Out-Null
# Settings for 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
# Set up the task for user apps
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -InputObject $task -Force | Out-Null
$ChangedSettings++
}
elseif ($null -eq $($WAUPolicies.WAU_UserContext) -and ($($WAUConfig.WAU_UserContext) -or $($WAUConfig.WAU_UserContext) -eq 0)) {
Remove-ItemProperty $regPath -Name WAU_UserContext -Force -ErrorAction SilentlyContinue | Out-Null
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
$ChangedSettings++
}
if ($ChangedSettings -gt 0) {
Write-Log "Changed settings: $ChangedSettings" "Yellow"
}