Files
punktfunk/docs/windows-service.md
T
enricobuehler 0ce2e37faf refactor(host/windows): clean up DDA path + add a proper Windows service
Final cleanup after the DDA-parity work, plus an end-user service to replace the
PsExec/VBS/scheduled-task launch chain.

Cleanup (behavior-preserving):
- sudovda.rs: drop the dead legacy GDI isolate_displays/restore_displays (CCD is
  the sole isolation path), the always-empty Monitor.isolated field, and the
  vestigial reassert_isolation + PUNKTFUNK_ISOLATE_DISPLAYS knob; fix stale comments.
- dxgi.rs: downgrade leftover debug warns/infos (DuplicateOutput1 retry, FALLBACKS,
  hook-hits, AcquireNextFrame idle timeout) to debug!; remove the PUNKTFUNK_NO_CURSOR
  per-frame test knob.

Windows service (src/service.rs, `punktfunk-host service`):
- SCM supervisor (windows-service crate) that duplicates its LocalSystem token,
  retargets it to the active console session, and CreateProcessAsUserW's the host
  there (Sunshine/Apollo model) — relaunching on exit and console session switch,
  inside a kill-on-close job object so a service crash never orphans the host.
- install/uninstall/start/stop/status subcommands: one elevated `service install`
  registers an auto-start LocalSystem service + firewall rules + a default host.env.
- Config moves to %ProgramData%\punktfunk\host.env; config_dir() now resolves to
  %ProgramData%\punktfunk on Windows (replacing the APPDATA=C:\Users\Public hack),
  with a PUNKTFUNK_CONFIG_DIR override. Logs land in %ProgramData%\punktfunk\logs\.
- merged_env_block (shared with the WGC helper) now also carries RUST_LOG.
- docs/windows-service.md + scripts/windows/host.env.example; windows-host.md updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-16 18:44:15 +00:00

4.0 KiB

Windows service (deployment)

The PunktfunkHost Windows service is the end-user way to run the host on Windows. It replaces the manual bring-up chain (a scheduled task → PsExec64 -s -i 1wscript launch.vbshost-run.cmd) with one command, auto-start on boot, and supervision.

Install

From an elevated (Administrator) prompt:

punktfunk-host service install   # register auto-start LocalSystem service + firewall rules + default host.env
punktfunk-host service start     # start it now (also starts automatically on every boot)

service install is idempotent — run it again after upgrading the exe to re-point the service at the new binary. Register whatever location you keep the exe in (e.g. C:\Program Files\punktfunk\); the service records the current exe path.

Other subcommands:

punktfunk-host service stop
punktfunk-host service status
punktfunk-host service uninstall   # stop + delete the service + remove its firewall rules

How it works

The host must run as SYSTEM in the interactive session (Session 1+): Desktop Duplication of the secure desktop (UAC / lock / login) and SendInput need SYSTEM, and capture/injection need the interactive session, which a plain Session-0 service is not in.

So the service (itself in Session 0) never captures. On start, and whenever the active console session changes, it:

  1. resolves the active console session (WTSGetActiveConsoleSessionId),
  2. duplicates its own LocalSystem token and retargets it to that session (SetTokenInformation TokenSessionId),
  3. launches the host there with CreateProcessAsUserW (lpDesktop = winsta0\default),
  4. supervises it: relaunches on exit/crash (with backoff) and on a console connect/disconnect.

A kill-on-close job object ensures a service crash never orphans the SYSTEM host. The host in turn spawns the WGC helper into the user session (see windows-secure-desktop.md) — two nested launches. Lock/unlock are handled inside the host (the DesktopWatcher DDA↔WGC mux), so the service deliberately does not relaunch on lock/unlock — only on a real session switch.

This is the same model Sunshine/Apollo use.

Configuration

Config lives in %ProgramData%\punktfunk\host.env (KEY=VALUE lines, # comments). service install writes a default if none exists. Template: scripts/windows/host.env.example.

PUNKTFUNK_ENCODER=nvenc
PUNKTFUNK_VIDEO_SOURCE=virtual
PUNKTFUNK_SECURE_DDA=1
RUST_LOG=info
# PUNKTFUNK_HOST_CMD=serve --native    # the host subcommand the service launches (default)

The service loads these into its environment and carries PUNKTFUNK_* + RUST_LOG to the host child (the same env-merge the WGC helper uses). Restart the service after editing:

punktfunk-host service stop; punktfunk-host service start

The host's identity (cert/pairing/mgmt token/library) also lives under %ProgramData%\punktfunk — a machine-wide dir the SYSTEM service and the interactive user share, surviving user logout. PUNKTFUNK_CONFIG_DIR overrides the location (both platforms; handy for tests).

Logs

  • %ProgramData%\punktfunk\logs\service.log — the service's own supervision log (spawn/exit/session switches).
  • %ProgramData%\punktfunk\logs\host.log — the host child's stdout/stderr.

Prerequisites

  • The host built with --features nvenc for NVENC (the driver ships nvEncodeAPI64.dll; no SDK needed at runtime). Software encode otherwise.
  • The SudoVDA indirect display driver installed (for PUNKTFUNK_VIDEO_SOURCE=virtual).
  • ViGEmBus for virtual gamepads (optional).

Gotchas

  • service install/uninstall need an elevated prompt (the SCM rejects non-admin).
  • service run is the SCM entry point — don't run it by hand (it errors with a hint).
  • A graceful stop currently TerminateProcesses the host, so its RAII teardown (SudoVDA monitor REMOVE) doesn't run; a stale virtual monitor can linger until the next start. A cooperative-stop signal is a follow-up.