MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / generateWindowsTaskXml

Function generateWindowsTaskXml

apps/cli/src/service.ts:656–694  ·  view source on GitHub ↗
(options: {
  readonly command: string;
  readonly arguments?: string;
  readonly userId: string;
  readonly boot?: boolean;
})

Source from the content-addressed store, hash-verified

654 * such dependency and a non-admin install succeeds.
655 */
656export const generateWindowsTaskXml = (options: {
657 readonly command: string;
658 readonly arguments?: string;
659 readonly userId: string;
660 readonly boot?: boolean;
661}): string => {
662 const user = xmlEscape(options.userId);
663 const trigger = options.boot
664 ? "<BootTrigger><Enabled>true</Enabled></BootTrigger>"
665 : `<LogonTrigger><Enabled>true</Enabled><UserId>${user}</UserId></LogonTrigger>`;
666 const logonType = options.boot ? "S4U" : "InteractiveToken";
667 const runLevel = options.boot ? "HighestAvailable" : "LeastPrivilege";
668 const action = options.arguments
669 ? `<Exec><Command>${xmlEscape(options.command)}</Command><Arguments>${xmlEscape(options.arguments)}</Arguments></Exec>`
670 : `<Exec><Command>${xmlEscape(options.command)}</Command></Exec>`;
671 return [
672 '<?xml version="1.0" encoding="UTF-16"?>',
673 '<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">',
674 " <RegistrationInfo><Description>Executor supervised daemon</Description></RegistrationInfo>",
675 ` <Triggers>${trigger}</Triggers>`,
676 " <Principals>",
677 ` <Principal id="Author"><UserId>${user}</UserId><LogonType>${logonType}</LogonType><RunLevel>${runLevel}</RunLevel></Principal>`,
678 " </Principals>",
679 " <Settings>",
680 " <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>",
681 " <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>",
682 " <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>",
683 " <StartWhenAvailable>true</StartWhenAvailable>",
684 " <RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure>",
685 " <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>",
686 " <Enabled>true</Enabled>",
687 " </Settings>",
688 ' <Actions Context="Author">',
689 ` ${action}`,
690 " </Actions>",
691 "</Task>",
692 "",
693 ].join("\r\n");
694};
695
696/**
697 * A tiny VBScript shim the task runs via `wscript.exe`. The default (logon) task

Callers 2

service.test.tsFile · 0.90
makeWindowsBackendFunction · 0.85

Calls 1

xmlEscapeFunction · 0.70

Tested by

no test coverage detected