From 8077181dcef7246f8c2a82a3a53cbdff6acbf477 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Fri, 6 Feb 2026 13:51:43 +0300 Subject: [PATCH] Fix Windows Task Scheduler auto-start - Auto-detect Python executable path instead of hardcoded "python" - Add error handling if Python not found in PATH - Add ErrorAction to prevent errors on unregister - Fixes "file not found" error (0x80070002) on system startup Co-Authored-By: Claude Sonnet 4.5 --- media_server/service/install_task_windows.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/media_server/service/install_task_windows.ps1 b/media_server/service/install_task_windows.ps1 index ffef890..7f67f34 100644 --- a/media_server/service/install_task_windows.ps1 +++ b/media_server/service/install_task_windows.ps1 @@ -1,8 +1,16 @@ -Unregister-ScheduledTask -TaskName "MediaServer" -Confirm:$false +Unregister-ScheduledTask -TaskName "MediaServer" -Confirm:$false -ErrorAction SilentlyContinue # Get the project root directory (two levels up from this script) $projectRoot = (Get-Item $PSScriptRoot).Parent.Parent.FullName -$action = New-ScheduledTaskAction -Execute "python" -Argument "-m media_server.main" -WorkingDirectory $projectRoot + +# Find Python executable +$pythonPath = (Get-Command python -ErrorAction SilentlyContinue).Source +if (-not $pythonPath) { + Write-Error "Python not found in PATH. Please ensure Python is installed and accessible." + exit 1 +} + +$action = New-ScheduledTaskAction -Execute $pythonPath -Argument "-m media_server.main" -WorkingDirectory $projectRoot $trigger = New-ScheduledTaskTrigger -AtStartup $principal = New-ScheduledTaskPrincipal -UserId "$env:USERNAME" -LogonType S4U -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable