[PR #4218] [MERGED] Servers: "Run in the background and at login" works on Windows without admin rights #5493

Closed
opened 2026-11-03 05:12:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4218
Author: @DenisHumen
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/server-service-windows


📝 Commits (1)

  • e3e2404 horizon-server: install the Windows logon task without admin rights

📊 Changes

1 file changed (+133 additions, -5 deletions)

View changed files

📝 crates/horizon-server/src/service.rs (+133 -5)

📄 Description

🤖 Opened by DenisHumen's AI agent (Claude Code, Opus 5.5), not by DenisHumen personally.

What

On Windows, horizon-server service install now creates its logon task from XML. The task's LogonTrigger and principal name the current user (DOMAIN\user, interactive token, LeastPrivilege). It used to run schtasks /Create /SC ONLOGON.

service install is what the launcher's Run in the background and at login switch runs (Servers page → server_command(["service", "install"])).

Why

/SC ONLOGON makes a trigger that fires at every user's logon, and only an administrator can create that. When the launcher runs as a normal user, the switch fails with "Access is denied", which is what #3733 reports. Checked on Windows 11 Pro 10.0.26200, not elevated:

command result
schtasks /Create /TN probe /TR "cmd /c exit 0" /SC ONLOGON /RL LIMITED /F (what main runs) Access is denied
same with /RU %USERNAME% /IT Access is denied
schtasks /Create /TN probe /XML task.xml /F, trigger and principal naming the user created, /Run works

This is a launcher/server feature with no vanilla counterpart. The behaviour the UI promises ("starts when you log in to this computer, keeps running when the launcher closes, and comes back by itself") comes from the module doc and the switch's own text.

The XML also drops two schtasks /Create defaults that would stop a server: the 72-hour run limit (ExecutionTimeLimit is now PT0S) and not starting on battery. It adds RestartOnFailure (every minute), matching the systemd unit's Restart=on-failure and launchd's KeepAlive. schtasks /XML reads only UTF-16, so the file is written as UTF-16LE with a BOM. It goes to the temp folder and is deleted right after.

Checked

  • New unit test windows_tasks_start_at_the_users_own_logon: the trigger and the principal carry the user, paths are XML-escaped, there is no time limit, and the file is UTF-16LE with a BOM.
  • New #[ignore]d Windows test windows_task_installs_without_elevation creates and deletes a real task as the current, unelevated user. It passes here (cargo test -p horizon-server service:: -- --include-ignored).
  • End to end on Windows 11, not elevated: horizon-server init in a scratch folder, then service install → "Installed the task horizon-server-…"; schtasks /Query /V shows the task as Running, schedule "At logon", running the supervisor with --dir … run. Then service uninstall removed the task (query fails afterwards) and no horizon-server process was left. On main, the same install fails at schtasks /Create with "Access is denied".
  • cargo clippy -p horizon-server --all-targets -- -D warnings -A clippy::manual_range_contains -A clippy::nonminimal_bool -A clippy::overly_complex_bool_expr is clean.

Known failures in the pr_ready block below, all unrelated to this change and failing the same way on main on Windows:

  • clippy: rust 1.96's manual_range_contains in horizon-world.
  • service::tests::units_run_the_supervisor fails on Windows because dir.join("logs/supervisor.log") writes a \. That test and launchd_plist are untouched here.
  • Parity: tools/parity.py needs fcntl, which Windows lacks. This change is in horizon-server only, outside the game.

Fixes #3733

pr_ready

pr_ready (tools/pr_ready.py --base upstream/main on DenisPC, against upstream/main at bd9b32587, 1 min 57 s)

Check Result
Scope ✅ 1 files, +133 −5
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (1 min 1 s)
rustfmt ✅ (7 s)
clippy ❌ failed (32 s)
tests: horizon-server ❌ 44 passed, 1 failed (11 s)
doc tests ➖ no library touched
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ❌ 362 affected, (1 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4218 **Author:** [@DenisHumen](https://github.com/DenisHumen) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/server-service-windows` --- ### 📝 Commits (1) - [`e3e2404`](https://github.com/horizon-rust/horizon/commit/e3e2404a1f73a8eaed29b1bc0056b4af4cb6a594) horizon-server: install the Windows logon task without admin rights ### 📊 Changes **1 file changed** (+133 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-server/src/service.rs` (+133 -5) </details> ### 📄 Description > 🤖 Opened by DenisHumen's AI agent (Claude Code, Opus 5.5), not by DenisHumen personally. ## What On Windows, `horizon-server service install` now creates its logon task from XML. The task's `LogonTrigger` and principal name the current user (`DOMAIN\user`, interactive token, `LeastPrivilege`). It used to run `schtasks /Create /SC ONLOGON`. `service install` is what the launcher's **Run in the background and at login** switch runs (Servers page → `server_command(["service", "install"])`). ## Why `/SC ONLOGON` makes a trigger that fires at **every** user's logon, and only an administrator can create that. When the launcher runs as a normal user, the switch fails with "Access is denied", which is what #3733 reports. Checked on Windows 11 Pro 10.0.26200, not elevated: | command | result | | --- | --- | | `schtasks /Create /TN probe /TR "cmd /c exit 0" /SC ONLOGON /RL LIMITED /F` (what main runs) | Access is denied | | same with `/RU %USERNAME% /IT` | Access is denied | | `schtasks /Create /TN probe /XML task.xml /F`, trigger and principal naming the user | created, `/Run` works | This is a launcher/server feature with no vanilla counterpart. The behaviour the UI promises ("starts when you log in to this computer, keeps running when the launcher closes, and comes back by itself") comes from the module doc and the switch's own text. The XML also drops two `schtasks /Create` defaults that would stop a server: the 72-hour run limit (`ExecutionTimeLimit` is now `PT0S`) and not starting on battery. It adds `RestartOnFailure` (every minute), matching the systemd unit's `Restart=on-failure` and launchd's `KeepAlive`. `schtasks /XML` reads only UTF-16, so the file is written as UTF-16LE with a BOM. It goes to the temp folder and is deleted right after. ## Checked - New unit test `windows_tasks_start_at_the_users_own_logon`: the trigger and the principal carry the user, paths are XML-escaped, there is no time limit, and the file is UTF-16LE with a BOM. - New `#[ignore]`d Windows test `windows_task_installs_without_elevation` creates and deletes a real task as the current, unelevated user. It passes here (`cargo test -p horizon-server service:: -- --include-ignored`). - End to end on Windows 11, not elevated: `horizon-server init` in a scratch folder, then `service install` → "Installed the task horizon-server-…"; `schtasks /Query /V` shows the task as Running, schedule "At logon", running the supervisor with `--dir … run`. Then `service uninstall` removed the task (query fails afterwards) and no `horizon-server` process was left. On main, the same `install` fails at `schtasks /Create` with "Access is denied". - `cargo clippy -p horizon-server --all-targets -- -D warnings -A clippy::manual_range_contains -A clippy::nonminimal_bool -A clippy::overly_complex_bool_expr` is clean. Known failures in the pr_ready block below, all unrelated to this change and failing the same way on main on Windows: - clippy: rust 1.96's `manual_range_contains` in `horizon-world`. - `service::tests::units_run_the_supervisor` fails on Windows because `dir.join("logs/supervisor.log")` writes a `\`. That test and `launchd_plist` are untouched here. - Parity: `tools/parity.py` needs `fcntl`, which Windows lacks. This change is in `horizon-server` only, outside the game. Fixes #3733 <details><summary>pr_ready</summary> **pr_ready** (`tools/pr_ready.py --base upstream/main` on DenisPC, against upstream/main at bd9b32587, 1 min 57 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +133 −5 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (1 min 1 s) | | rustfmt | ✅ (7 s) | | clippy | ❌ failed (32 s) | | tests: horizon-server | ❌ 44 passed, 1 failed (11 s) | | doc tests | ➖ no library touched | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ❌ 362 affected, (1 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:12:58 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5493
No description provided.