schtasks automatically enables "Stop the task if it runs longer than 3 days"
Asked Answered
S

1

7

I use the batch script to create a scheduled task:

schtasks /Create /F /RL highest /SC onlogon /TR "C:\MyFile.exe" /TN "MyDescription"

It perfectly runs my application on every user logon. However, it automatically enables "Stop the task if it runs longer than" option with "3 days". I think it is default behavior.

My application may run on servers and it should not quit after 3 days. How can I modify the batch script so that my application runs infinitely?

Smalto answered 8/10, 2021 at 19:10 Comment(2)
I don't see anything in the help file to control unchecking that box but I am wondering if the /DU option would allow you to extend the length of time before the task is killed.Dovap
I'm not aware of any command line option to modify this behavior. If you create the task via an XML description file using the /XML option, however, you can place <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> in the SettingsBarometry
F
4

thanks to @anon coward's comment, I was able to get this made:

<?xml version="1.0" ?>
<!--
This sample schedules a task to start notepad.exe when after login.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
    <RegistrationInfo>
        <Date>2022-11-16T00:00:00-00:00</Date>
        <Author>It's a me, Mario</Author>
        <Version>0.0.1</Version>
        <Description>Bowser watch daemon</Description>
    </RegistrationInfo>
    <Triggers>
        <LogonTrigger>
            <StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
            <EndBoundary>2060-01-01T00:00:00-08:00</EndBoundary>
            <Enabled>true</Enabled>
            <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
        </LogonTrigger>
    </Triggers>
    <Settings>
        <Enabled>true</Enabled>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <AllowHardTerminate>true</AllowHardTerminate>
        <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
        <Hidden>true</Hidden>
        <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
        <RunOnlyIfIdle>false</RunOnlyIfIdle>
        <IdleSettings>
            <StopOnIdleEnd>false</StopOnIdleEnd>
            <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
    </Settings>
    <Actions>
        <Exec>
            <Command>notepad.exe</Command>
        </Exec>
    </Actions>
</Task>

run with: schtasks /Create /XML <xmlpath> /TN "BowserWatch"

Firenew answered 17/11, 2022 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.