5

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?

Xel Naga
  • 826
  • 11
  • 28
  • 1
    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. – Squashman Oct 08 '21 at 19:22
  • 2
    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 `PT0S` in the Settings – Anon Coward Oct 11 '21 at 15:57

1 Answers1

2

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"

nmz787
  • 1,960
  • 1
  • 21
  • 35