KtvSetup/install.ps1

28 lines
1.1 KiB
PowerShell
Raw Normal View History

2025-05-22 13:57:37 +08:00
# Set up target folder
2025-05-22 09:03:51 +08:00
$targetDir = "C:\scripts"
if (-not (Test-Path $targetDir)) {
New-Item -Path $targetDir -ItemType Directory | Out-Null
}
2025-05-22 13:57:37 +08:00
# Always overwrite heartbeat.ps1
$source1 = Resolve-Path ".\scripts\heartbeat.ps1"
$dest1 = "$targetDir\heartbeat.ps1"
Copy-Item $source1 -Destination $dest1 -Force
2025-05-22 09:03:51 +08:00
2025-05-22 13:57:37 +08:00
# Only copy config.json if it does not exist
$source2 = Resolve-Path ".\scripts\config.json"
$dest2 = "$targetDir\config.json"
if (-not (Test-Path $dest2)) {
Copy-Item $source2 -Destination $dest2 -Force
}
# Set up scheduled task to run on system startup
2025-05-22 09:03:51 +08:00
$taskName = "KtvHeartbeat"
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"$targetDir\heartbeat.ps1`""
$trigger = New-ScheduledTaskTrigger -AtStartup
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest
Register-ScheduledTask -Action $action -Trigger $trigger -Principal $principal -TaskName $taskName -Force
2025-05-22 13:57:37 +08:00
Write-Host "ok Installation Complete: The script has been deployed and will run at system startup." -ForegroundColor Green