Fix task script

This commit is contained in:
2025-07-14 08:28:51 +02:00
parent 7173d2c6f5
commit 4115cb9cb7

66
create_journaler_task.ps1 Normal file
View File

@@ -0,0 +1,66 @@
# Run this script as administrator
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Please run this script as Administrator" -ForegroundColor Red
exit 1
}
# Get the directory where the script is located
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$journalerPath = Join-Path $scriptPath "src-tauri\target\release\journaler.exe"
$workingDir = Split-Path -Parent $journalerPath
# Verify journaler.exe exists
if (-not (Test-Path $journalerPath)) {
Write-Host "Error: journaler.exe not found at: $journalerPath" -ForegroundColor Red
Write-Host "Please make sure you've built the release version of journaler" -ForegroundColor Yellow
exit 1
}
# Task settings
$taskName = "RunJournalerPeriodically"
$taskDescription = "Runs Journaler every 10 minutes"
try {
# Remove existing task if it exists
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
# Create the task action (with working directory)
$action = New-ScheduledTaskAction -Execute $journalerPath -WorkingDirectory $workingDir
# Create trigger (every 10 minutes)
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 10)
# Get current user for the task
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
# Set principal (run as current user when logged in)
$principal = New-ScheduledTaskPrincipal -UserId $currentUser -LogonType Interactive -RunLevel Highest
# Set settings (more permissive)
$settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-ExecutionTimeLimit (New-TimeSpan -Minutes 0) `
-RestartCount 3 `
-RestartInterval (New-TimeSpan -Minutes 1)
# Register the task
Register-ScheduledTask -TaskName $taskName -Description $taskDescription `
-Action $action -Trigger $trigger -Principal $principal -Settings $settings
Write-Host "Successfully created scheduled task: $taskName" -ForegroundColor Green
Write-Host "Journaler will run every 10 minutes" -ForegroundColor Green
Write-Host "Task will run as user: $currentUser" -ForegroundColor Green
# Start the task immediately
Start-ScheduledTask -TaskName $taskName
Write-Host "Task started manually" -ForegroundColor Green
# Show task status
$task = Get-ScheduledTask -TaskName $taskName
Write-Host "Current task state: $($task.State)" -ForegroundColor Cyan
} catch {
Write-Host "Error creating scheduled task: $_" -ForegroundColor Red
exit 1
}