(input: BuildScheduledTaskXmlInput)
| 19 | } |
| 20 | |
| 21 | export function buildScheduledTaskXml(input: BuildScheduledTaskXmlInput): string { |
| 22 | const description = escapeXmlText(input.description); |
| 23 | const command = escapeXmlText(input.command); |
| 24 | const args = input.arguments ? escapeXmlText(input.arguments) : ''; |
| 25 | |
| 26 | const principalLogon = input.taskUser |
| 27 | ? `\n <UserId>${escapeXmlText(input.taskUser)}</UserId>\n <LogonType>InteractiveToken</LogonType>` |
| 28 | : '\n <GroupId>S-1-5-32-545</GroupId>'; |
| 29 | const triggerUser = input.taskUser |
| 30 | ? `\n <UserId>${escapeXmlText(input.taskUser)}</UserId>` |
| 31 | : ''; |
| 32 | const argumentsXml = args ? `\n <Arguments>${args}</Arguments>` : ''; |
| 33 | |
| 34 | return `<?xml version="1.0" encoding="UTF-16"?> |
| 35 | <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> |
| 36 | <RegistrationInfo> |
| 37 | <Description>${description}</Description> |
| 38 | </RegistrationInfo> |
| 39 | <Triggers> |
| 40 | <LogonTrigger> |
| 41 | <Enabled>true</Enabled>${triggerUser} |
| 42 | </LogonTrigger> |
| 43 | </Triggers> |
| 44 | <Principals> |
| 45 | <Principal id="Author">${principalLogon} |
| 46 | <RunLevel>LeastPrivilege</RunLevel> |
| 47 | </Principal> |
| 48 | </Principals> |
| 49 | <Settings> |
| 50 | <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> |
| 51 | <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> |
| 52 | <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> |
| 53 | <AllowHardTerminate>true</AllowHardTerminate> |
| 54 | <StartWhenAvailable>false</StartWhenAvailable> |
| 55 | <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> |
| 56 | <IdleSettings> |
| 57 | <StopOnIdleEnd>false</StopOnIdleEnd> |
| 58 | <RestartOnIdle>false</RestartOnIdle> |
| 59 | </IdleSettings> |
| 60 | <AllowStartOnDemand>true</AllowStartOnDemand> |
| 61 | <Enabled>true</Enabled> |
| 62 | <Hidden>false</Hidden> |
| 63 | <RunOnlyIfIdle>false</RunOnlyIfIdle> |
| 64 | <WakeToRun>false</WakeToRun> |
| 65 | <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> |
| 66 | <Priority>7</Priority> |
| 67 | </Settings> |
| 68 | <Actions Context="Author"> |
| 69 | <Exec> |
| 70 | <Command>${command}</Command>${argumentsXml} |
| 71 | </Exec> |
| 72 | </Actions> |
| 73 | </Task>`; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | export function parseSchtasksQuery(output: string): Record<string, string> | undefined { |
no test coverage detected