User context scheduled task added with app delta
parent
d7874e36f3
commit
8f39ea3ed1
|
@ -261,6 +261,15 @@ function Install-WingetAutoUpdate {
|
||||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTriggers
|
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTriggers
|
||||||
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force | Out-Null
|
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -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
|
||||||
|
|
||||||
# Settings for the scheduled task for Notifications
|
# Settings for the scheduled task for Notifications
|
||||||
$taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
$taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
||||||
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
|
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
|
||||||
|
@ -270,6 +279,14 @@ function Install-WingetAutoUpdate {
|
||||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||||
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force | Out-Null
|
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force | Out-Null
|
||||||
|
|
||||||
|
#Set task readable/runnable for all users
|
||||||
|
$scheduler = New-Object -ComObject "Schedule.Service"
|
||||||
|
$scheduler.Connect()
|
||||||
|
$task = $scheduler.GetFolder("").GetTask("Winget-AutoUpdate")
|
||||||
|
$sec = $task.GetSecurityDescriptor(0xF)
|
||||||
|
$sec = $sec + '(A;;GRGX;;;AU)'
|
||||||
|
$task.SetSecurityDescriptor($sec, 0)
|
||||||
|
|
||||||
# Configure Reg Key
|
# Configure Reg Key
|
||||||
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
||||||
New-Item $regPath -Force | Out-Null
|
New-Item $regPath -Force | Out-Null
|
||||||
|
|
|
@ -52,5 +52,11 @@ function Get-WingetOutdatedApps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#If current user is not system, remove system apps from list
|
||||||
|
if ($currentPrincipal -eq $true) {
|
||||||
|
$SystemApps = Get-Content -Path "$WorkingDir\winget_system_apps.txt"
|
||||||
|
$upgradeList = $upgradeList | Where-Object {$SystemApps -notcontains $_}
|
||||||
|
}
|
||||||
|
|
||||||
return $upgradeList | Sort-Object {Get-Random}
|
return $upgradeList | Sort-Object {Get-Random}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
function Get-WingetSystemApps {
|
||||||
|
|
||||||
|
#if not "Interactive" user, run as system
|
||||||
|
if ($currentPrincipal -eq $false) {
|
||||||
|
|
||||||
|
#Json File where to export system installed apps
|
||||||
|
$jsonFile = "$WorkingDir\winget_system_apps.txt"
|
||||||
|
|
||||||
|
#Get list of installed Winget apps to json file
|
||||||
|
& $Winget export -o $jsonFile --accept-source-agreements | Out-Null
|
||||||
|
|
||||||
|
#Convert json file to txt file with app ids
|
||||||
|
$InstalledApps = get-content $jsonFile | ConvertFrom-Json
|
||||||
|
|
||||||
|
#Return app list
|
||||||
|
Set-Content $InstalledApps.Sources.Packages.PackageIdentifier -Path $jsonFile
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,9 @@ function Start-Init {
|
||||||
#Config console output encoding
|
#Config console output encoding
|
||||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
|
#Check if running account is system or interactive logon
|
||||||
|
$Script:currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
|
||||||
|
|
||||||
#Log Header
|
#Log Header
|
||||||
$Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
|
$Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
|
||||||
$Log | Write-host
|
$Log | Write-host
|
||||||
|
|
|
@ -22,9 +22,6 @@ function Start-NotifTask ($Title, $Message, $MessageType, $Balise, $OnClickActio
|
||||||
<tag>$Balise</tag>
|
<tag>$Balise</tag>
|
||||||
</toast>
|
</toast>
|
||||||
"@
|
"@
|
||||||
|
|
||||||
#Check if running account is system or interactive logon
|
|
||||||
$currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
|
|
||||||
|
|
||||||
#if not "Interactive" user, run as system
|
#if not "Interactive" user, run as system
|
||||||
if ($currentPrincipal -eq $false) {
|
if ($currentPrincipal -eq $false) {
|
||||||
|
|
|
@ -139,6 +139,12 @@ if (Test-Network) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#Run WAU in user context if currently as system
|
||||||
|
if ($currentPrincipal -eq $false) {
|
||||||
|
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
#End
|
#End
|
||||||
Write-Log "End of process!" "Cyan"
|
Write-Log "End of process!" "Cyan"
|
||||||
Start-Sleep 3
|
Start-Sleep 3
|
Loading…
Reference in New Issue