我使用批处理脚本创建计划任务:
schtasks /Create /F /RL highest /SC onlogon /TR "C:\MyFile.exe" /TN "MyDescription"
它可以在每次用户登录时完美运行我的应用程序。但是,它会自动启用“如果任务运行时间超过”则停止任务“3 天”选项。我认为这是默认行为。
我的应用程序可能在服务器上运行,并且 3 天后不应退出。如何修改批处理脚本以便我的应用程序无限运行?
感谢@anon coward的评论,我能够做到这一点:
<?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>
运行:
schtasks /Create /XML <xmlpath> /TN "BowserWatch"