Aggiunge script registrazione task UTF16

This commit is contained in:
2026-07-02 11:16:47 +02:00
parent 5d106c9dc6
commit bb4d26083f
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
param(
[Parameter(Mandatory = $true)]
[ValidateSet("Notifier", "BackupOnLogoff")]
[string]$Task,
[string]$TaskFolder = "BakRest"
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
if ($Task -eq "Notifier") {
$taskName = "$TaskFolder\ServerNotifierEvery30Minutes"
$xmlPath = Join-Path $repoRoot "tasks\BakRestServerNotifierEvery30Minutes.xml"
} else {
$taskName = "$TaskFolder\BackupOnLogoff"
$xmlPath = Join-Path $repoRoot "tasks\BakRestBackupOnLogoff.xml"
}
if (-not (Test-Path -LiteralPath $xmlPath)) {
throw "Task XML not found: $xmlPath"
}
$xml = Get-Content -LiteralPath $xmlPath -Raw
$xml = $xml -replace 'encoding="UTF-8"', 'encoding="UTF-16"'
$tempXml = Join-Path $env:TEMP ("bakrest-task-{0}.xml" -f ([Guid]::NewGuid()))
[System.IO.File]::WriteAllText($tempXml, $xml, [System.Text.Encoding]::Unicode)
try {
schtasks.exe /Create /TN $taskName /XML $tempXml /F
if ($LASTEXITCODE -ne 0) {
throw "schtasks failed with exit code $LASTEXITCODE"
}
Write-Host "Registered task: $taskName"
} finally {
Remove-Item -LiteralPath $tempXml -Force -ErrorAction SilentlyContinue
}