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

Function generateWindowsTaskXml

apps/cli/src/service.ts:663–701  ·  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

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