我正在遵循有关使用任务计划程序创建以XML定义的任务的Microsoft官方文档的示例。我的目标是实现在系统启动时启动记事本的示例。
按照文档中的步骤,我已经创建了一个XML文件,其中包含上面链接的内容,并将其放在中C:\start-notepad.xml
。要注册任务,我以管理员身份打开PowerShell并运行
PS C:\> schtasks /create /XML start-notepad.xml /tn start-notepad
SUCCESS: The scheduled task "start-notepad" has successfully been created.
PS C:\> schtasks /Query /tn start-notepad
Folder: \
TaskName Next Run Time Status
======================================== ====================== ===============
start-notepad N/A Ready
现在,当我重新启动计算机(VirtualBox上的VM)时,我希望记事本应用程序启动,但不会启动。说明文件缺少某些内容,或者我做错了...
<?xml version="1.0" ?>
<!--
This sample schedules a task to start notepad.exe when
the system is booted.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2005-10-11T13:21:17-08:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Starts Notepad on system boot.</Description>
</RegistrationInfo>
<Triggers>
<BootTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2026-01-01T00:00:00-08:00</EndBoundary>
<Enabled>true</Enabled>
<ExecutionTimeLimit>PT5M</ExecutionTimeLimit>
</BootTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>
该任务已正确添加到任务计划程序中,但是当我单击“运行”时没有任何反应,重新启动时也没有...
我通过更改2件事找到了解决方案:
LogonTrigger
旁边的BootTrigger
建议的解决方案在这里:https : //www.sevenforums.com/tutorials/67503-task-create-run-program-startup-log.html
我更换了:
<Triggers>
<BootTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2026-01-01T00:00:00-08:00</EndBoundary>
<Enabled>true</Enabled>
<ExecutionTimeLimit>PT5M</ExecutionTimeLimit>
</BootTrigger>
</Triggers>
和:
<Triggers>
<BootTrigger>
<Enabled>true</Enabled>
</BootTrigger>
<LogonTrigger>
<Enabled>true</Enabled>
</LogonTrigger>
</Triggers>
Principal
我发现,除非使用当前登录的用户,否则记事本将永远不会在启动(或登录)时启动。在此答案中,我发现了builtin\users
无论使用哪个用户登录,都可以使用来启动记事本的建议。
我更换了:
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
和:
<Principal>
<GroupId>S-1-5-32-545</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
您可以GrouId
在此处找到有关此内容的更多信息:https : //support.microsoft.com/zh-cn/help/243330/well-known-security-identifiers-in-windows-operating-systems
<?xml version="1.0" ?>
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-07-29T00:00:00-00:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Starts Notepad on system boot.</Description>
</RegistrationInfo>
<Triggers>
<BootTrigger>
<Enabled>true</Enabled>
</BootTrigger>
<LogonTrigger>
<Enabled>true</Enabled>
</LogonTrigger>
</Triggers>
<Principals>
<Principal>
<GroupId>S-1-5-32-545</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句