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

Function makeWindowsBackend

apps/cli/src/service.ts:803–943  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

801 });
802
803const makeWindowsBackend = (): ServiceBackend => {
804 const controlDir = (path: Path.Path): string =>
805 path.join(resolveExecutorDataDir(path), "server-control");
806 const taskXmlPath = (path: Path.Path): string => path.join(controlDir(path), "run-daemon.xml");
807 const wrapperCmdPath = (path: Path.Path): string => path.join(controlDir(path), "run-daemon.cmd");
808 const launcherVbsPath = (path: Path.Path): string =>
809 path.join(controlDir(path), "run-daemon.vbs");
810
811 return {
812 platform: "win32",
813 automated: true,
814 install: (descriptor) =>
815 Effect.gen(function* () {
816 const fs = yield* FileSystem.FileSystem;
817 const path = yield* Path.Path;
818 const dataDir = resolveExecutorDataDir(path);
819 const logs = serviceLogDir(path);
820 const control = path.join(dataDir, "server-control");
821 yield* fs.makeDirectory(logs, { recursive: true });
822 yield* fs.makeDirectory(control, { recursive: true });
823
824 const wrapperPath = wrapperCmdPath(path);
825 yield* fs.writeFileString(
826 wrapperPath,
827 generateWindowsDaemonWrapper(descriptor, dataDir, logs),
828 );
829
830 // Launch the wrapper through a hidden wscript shim so the logon task
831 // doesn't flash a console window on the interactive desktop each login.
832 const vbsPath = launcherVbsPath(path);
833 yield* fs.writeFileString(vbsPath, generateWindowsHiddenLauncherVbs(wrapperPath));
834
835 const xmlPath = taskXmlPath(path);
836 yield* writeUtf16File(
837 xmlPath,
838 generateWindowsTaskXml({
839 command: "wscript.exe",
840 arguments: `"${vbsPath}"`,
841 userId: windowsTaskUserId(),
842 boot: descriptor.boot ?? false,
843 }),
844 );
845
846 const create = yield* runSchtasks([
847 "/create",
848 "/tn",
849 WINDOWS_TASK_NAME,
850 "/xml",
851 xmlPath,
852 "/f",
853 ]);
854 if (create.code !== 0) {
855 // schtasks ends its messages with a period; drop it so the assembled
856 // sentence doesn't read "denied.. <hint>".
857 const detail = (create.stderr.trim() || create.stdout.trim()).replace(/\.\s*$/, "");
858 // The default (logon) task needs no elevation. Only the --boot path
859 // registers a boot/S4U task, which Task Scheduler refuses without
860 // Administrator — so point access-denial at the relevant fix.

Callers 1

getServiceBackendFunction · 0.85

Calls 15

resolveExecutorDataDirFunction · 0.90
serviceLogDirFunction · 0.85
wrapperCmdPathFunction · 0.85
launcherVbsPathFunction · 0.85
taskXmlPathFunction · 0.85
writeUtf16FileFunction · 0.85
generateWindowsTaskXmlFunction · 0.85
windowsTaskUserIdFunction · 0.85
runSchtasksFunction · 0.85
parseSchtasksRunningFunction · 0.85

Tested by

no test coverage detected