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
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 09:27:29 +08:00
|
|
|
|
# Copy setup-ftp.ps1 as well (假設放在 scripts 資料夾)
|
|
|
|
|
$source3 = Resolve-Path ".\scripts\setup-ftp.ps1"
|
|
|
|
|
$dest3 = "$targetDir\setup-ftp.ps1"
|
|
|
|
|
Copy-Item $source3 -Destination $dest3 -Force
|
|
|
|
|
|
|
|
|
|
# 執行 setup-ftp.ps1,需系統管理員權限
|
|
|
|
|
Write-Host "開始安裝 IIS FTP 服務..."
|
|
|
|
|
try {
|
|
|
|
|
& powershell.exe -ExecutionPolicy Bypass -File "$dest3"
|
|
|
|
|
Write-Host "FTP 服務安裝完成" -ForegroundColor Green
|
|
|
|
|
} catch {
|
|
|
|
|
Write-Host "FTP 服務安裝失敗:" $_.Exception.Message -ForegroundColor Red
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 13:57:37 +08:00
|
|
|
|
# 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-06-13 09:27:29 +08:00
|
|
|
|
Write-Host "ok Installation Complete: The script has been deployed and will run at system startup." -ForegroundColor Green
|