From 4115cb9cb71694f40ae9213caf605de564953c9f Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 14 Jul 2025 08:28:51 +0200 Subject: [PATCH] Fix task script --- create_journaler_task.ps1 | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 create_journaler_task.ps1 diff --git a/create_journaler_task.ps1 b/create_journaler_task.ps1 new file mode 100644 index 0000000..1932c16 --- /dev/null +++ b/create_journaler_task.ps1 @@ -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 +} \ No newline at end of file