> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Bach builds Windows installers from one bach.toml with the bach command: bach init, bach check, bach preview, bach build. Installs are per user and need no administrator rights by default. installer.scope = "machine" installs for every user after one Windows prompt. On Windows, run setup files with Start-Process -Wait -PassThru in PowerShell, and give signtool arguments that start with the word sign.

# [[services]]: Windows services

> Install Windows services with a machine-wide installer: start types, accounts, restarts, and how services behave during install, update and removal.

A Windows service is a program that runs in the background without anyone signed in, such as a sync agent or a local server. `[[services]]` installs one. Because that needs administrator rights, it requires `installer.scope = "machine"`.

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[installer]
scope = "machine"

[[services]]
name = "HelloAgent"
display_name = "Hello Agent"
description = "Syncs notes in the background."
file = "agent/agent.exe"
arguments = "--service"
```

Your program has to be written as a Windows service; Bach doesn't wrap ordinary programs.

| Setting | Default | Meaning |
| - | - | - |
| `name` | required | Service name: letters, digits, `.`, `-`, `_`, up to 64 characters, not starting with `.` |
| `display_name` | `name` | Name in the Services list, up to 256 characters |
| `description` | none | Up to 1000 characters |
| `file` | `app.executable` | A packaged `.exe` |
| `arguments` | none | Passed as written |
| `start` | `"auto"` | `"auto"` (with Windows), `"delayed"` (shortly after), `"manual"` or `"disabled"` |
| `account` | `"local_service"` | `"local_service"` (few rights, no network identity), `"network_service"` (computer's network identity) or `"local_system"` (full control; use only if needed). Other accounts aren't possible, since setup takes no password. |
| `restart_on_failure` | `true` | Windows restarts it a minute after it stops unexpectedly, up to three times; the count resets after a day |

## During setup

* **First install:** services are created, and `auto` or `delayed` ones started. One that doesn't start within 30 seconds fails the install, which is then undone.
* **Update:** running services are stopped (up to 30 seconds), files replaced, definitions updated, and services started again if they were running or `start` says so. Services no longer listed are removed. A failure restores the previous version.
* **Removal:** services are stopped and deleted before the files. A problem here is logged but doesn't stop removal.

Setup only changes a service whose program is in your install folder. If a service with that name already exists for something else, the install fails and the log names it.

`bach build --msi` refuses apps with services. `bach inspect` and [`bach diff`](/docs/reference/cli/diff) show them. On macOS, use [`[[macos.agents]]`](/docs/reference/config/macos).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.