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