-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstallChocoUpdateTray.ps1
27 lines (22 loc) · 1.27 KB
/
InstallChocoUpdateTray.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Install Script
$path = Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell\Scripts\"
New-Item -Path $path -Type Directory -force
Copy-Item ".\runChocoUpdateTray.vbs" $path
Copy-Item ".\ChocoUpdateTray.ps1" $path
$taskName = 'ChocoUpdateTray'
$taskDescription = "Check for chocolatey pdates and create tray icon"
$oneHtimespan = New-TimeSpan -Hours 1
$executable = Join-Path -Path $path -ChildPath "runChocoUpdateTray.vbs"
$A = New-ScheduledTaskAction -Execute $executable
$T = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval $oneHtimespan
$P = New-ScheduledTaskPrincipal $env:USERDOMAIN\$env:USERNAME -LogonType Interactive
$S = New-ScheduledTaskSettingsSet -Hidden -MultipleInstances IgnoreNew -ExecutionTimeLimit $oneHtimespan
$D = New-ScheduledTask -Action $A -Principal $P -Trigger $T -Settings $S -Description $taskDescription
$task = Get-ScheduledTask | Where-Object { $_.TaskName -eq $taskName } | Select-Object -First 1
if ($null -ne $task) {
$task | Unregister-ScheduledTask -Confirm:$false
Write-Host “Task $taskName was removed” -ForegroundColor Yellow
}
Register-ScheduledTask $taskName -InputObject $D
Write-Host “Task $taskName was added” -ForegroundColor Yellow
Start-ScheduledTask -TaskName $taskName