38 lines
1.3 KiB
PowerShell
38 lines
1.3 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$ExecutablePath
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$resolvedExecutable = (Resolve-Path -LiteralPath $ExecutablePath).Path
|
|
if ([System.IO.Path]::GetFileName($resolvedExecutable) -ne "Zcbot.WindowsNode.exe") {
|
|
throw "ExecutablePath must point to Zcbot.WindowsNode.exe"
|
|
}
|
|
|
|
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
$workingDirectory = Split-Path -Parent $resolvedExecutable
|
|
$action = New-ScheduledTaskAction `
|
|
-Execute $resolvedExecutable `
|
|
-WorkingDirectory $workingDirectory
|
|
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $currentUser
|
|
$principal = New-ScheduledTaskPrincipal `
|
|
-UserId $currentUser `
|
|
-LogonType Interactive `
|
|
-RunLevel Limited
|
|
$settings = New-ScheduledTaskSettingsSet `
|
|
-ExecutionTimeLimit ([TimeSpan]::Zero) `
|
|
-RestartCount 3 `
|
|
-RestartInterval (New-TimeSpan -Minutes 1) `
|
|
-MultipleInstances IgnoreNew
|
|
|
|
Register-ScheduledTask `
|
|
-TaskName "Zcbot Windows Node" `
|
|
-Description "Starts the zcbot Windows execution node after this account logs on." `
|
|
-Action $action `
|
|
-Trigger $trigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Force | Out-Null
|
|
|
|
Write-Output "[OK] Startup task registered for $currentUser."
|