我正在VB.NET中编写一个程序,它使用XML文档和schtasks.exe命令行工具创建最高权限的计划任务。我遇到的问题是哪个XML标记用于最高权限选项以及将其放在文档中的位置。当前文档如下,对于缩进感到遗憾(它没有正确导入):
<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>Admin Task</Description>
</RegistrationInfo>
<Triggers>
<!--
<CalendarTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2006-01-01T00:00:00-08:00</EndBoundary>
<Repetition>
<Interval>PT1M</Interval>
<Duration>PT4M</Duration>
</Repetition>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
-->
</Triggers>
<Principals>
<Principal id="Author">
<RunLevel>Highest</RunLevel><!--Not correct...-->
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>
PS:我对写XML非常缺乏经验。
答案 0 :(得分:0)
通过从计划任务中导出我需要的设置,我找到了正确的XML标记位置和语法。对于有类似问题的其他人,下面张贴了一个工作模板:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2014-04-13T16:02:17.9854869</Date>
<Author>[username]</Author>
</RegistrationInfo>
<Triggers />
<Principals>
<Principal id="Author">
<UserId>[username]</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>[command]</Command>
</Exec>
</Actions>
</Task>