stashapp/stash

[Feature] Create schedule task script

Closed this issue · 1 comments

Is your feature request related to a problem? Please describe.
Problems
When stash-win.exe is running, it creates a DOS window that continues to be displayed, instead of running in the background.
When I reboot my machine, I have to remember to startup stash-win.exe.

Solution
Add a script to the .stash folder that will create a schedule task.

I've created a generic script which can perform this task.
Here's the batch script:

set XML_File=CreateScheduleTaskForStash.xml
if exist %XML_File% del /Q %XML_File%

echo ^<?xml version="1.0" encoding="UTF-16"?^>>> %XML_File%
echo ^<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"^>>> %XML_File%
echo   ^<RegistrationInfo^>>> %XML_File%
echo     ^<Author^>%USERDOMAIN%\%USERNAME%^</Author^>>> %XML_File%
echo     ^<URI^>\Stash_Run^</URI^>>> %XML_File%
echo   ^</RegistrationInfo^>>> %XML_File%
echo   ^<Triggers^>>> %XML_File%
echo     ^<TimeTrigger^>>> %XML_File%
echo       ^<Repetition^>>> %XML_File%
echo         ^<Interval^>PT1H^</Interval^>>> %XML_File%
echo         ^<StopAtDurationEnd^>false^</StopAtDurationEnd^>>> %XML_File%
echo       ^</Repetition^>>> %XML_File%
echo       ^<StartBoundary^>2020-01-01T01:00:00^</StartBoundary^>>> %XML_File%
echo       ^<Enabled^>true^</Enabled^>>> %XML_File%
echo     ^</TimeTrigger^>>> %XML_File%
echo     ^<LogonTrigger^>>> %XML_File%
echo        ^<Enabled^>true^</Enabled^>>> %XML_File%
echo     ^</LogonTrigger^>>> %XML_File%
echo   ^</Triggers^>>> %XML_File%
echo   ^<Principals^>>> %XML_File%
echo     ^<Principal id="Author"^>>> %XML_File%
echo       ^<LogonType^>InteractiveToken^</LogonType^>>> %XML_File%
echo       ^<RunLevel^>LeastPrivilege^</RunLevel^>>> %XML_File%
echo     ^</Principal^>>> %XML_File%
echo   ^</Principals^>>> %XML_File%
echo   ^<Settings^>>> %XML_File%
echo     ^<MultipleInstancesPolicy^>IgnoreNew^</MultipleInstancesPolicy^>>> %XML_File%
echo     ^<DisallowStartIfOnBatteries^>true^</DisallowStartIfOnBatteries^>>> %XML_File%
echo     ^<StopIfGoingOnBatteries^>true^</StopIfGoingOnBatteries^>>> %XML_File%
echo     ^<AllowHardTerminate^>true^</AllowHardTerminate^>>> %XML_File%
echo     ^<StartWhenAvailable^>true^</StartWhenAvailable^>>> %XML_File%
echo     ^<RunOnlyIfNetworkAvailable^>false^</RunOnlyIfNetworkAvailable^>>> %XML_File%
echo     ^<IdleSettings^>>> %XML_File%
echo       ^<StopOnIdleEnd^>true^</StopOnIdleEnd^>>> %XML_File%
echo       ^<RestartOnIdle^>false^</RestartOnIdle^>>> %XML_File%
echo     ^</IdleSettings^>>> %XML_File%
echo     ^<AllowStartOnDemand^>true^</AllowStartOnDemand^>>> %XML_File%
echo     ^<Enabled^>true^</Enabled^>>> %XML_File%
echo     ^<Hidden^>false^</Hidden^>>> %XML_File%
echo     ^<RunOnlyIfIdle^>false^</RunOnlyIfIdle^>>> %XML_File%
echo     ^<WakeToRun^>true^</WakeToRun^>>> %XML_File%
echo     ^<ExecutionTimeLimit^>PT0S^</ExecutionTimeLimit^>>> %XML_File%
echo     ^<Priority^>7^</Priority^>>> %XML_File%
echo   ^</Settings^>>> %XML_File%
echo   ^<Actions Context="Author"^>>> %XML_File%
echo     ^<Exec^>>> %XML_File%
echo       ^<Command^>%CD%\stash-win.exe^</Command^>>> %XML_File%
echo     ^</Exec^>>> %XML_File%
echo   ^</Actions^>>> %XML_File%
echo ^</Task^>>> %XML_File%

schtasks /Create /XML %XML_File% /TN "Stash_Run"
schtasks /run /TN "Stash_Run"

As long as this script is executed in the same directory which stash-win.exe is in, it will create an XML file having the correct fully qualified path for the executable.
The scheduled task will execute stash-win.exe on an hourly basis if stash-win.exe is not already running, and it will run it in the background. No DOS window displayed.

After updating Stash and rebooting my machine, the scheduler is no longer starting the task in the background.
I'm closing this post until I can figure out what's going wrong.