> ## 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.

# Run programs during setup

> Run a program from your app during install or removal, such as a runtime installer or a first-time setup step, including with administrator rights.

Copying files is usually enough. Sometimes something else has to happen: installing a runtime, creating a database, registering with another tool. `[[run]]` runs one of your packaged programs during setup. This page explains when it runs, what happens when it fails, and when you need administrator rights.

Bach only runs programs that are part of your app. It can't run scripts that live elsewhere on the user's computer, and it doesn't go through a command shell.

## A first example

Your build folder contains a program that prepares a data folder:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
build/
  hello-notes.exe
  tools/
    setup-database.exe
```

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[[run]]
name = "Notes database"
file = "tools/setup-database.exe"
arguments = "--create"
```

During install and every update, after the files are in place, the window shows **Setting up Notes database** while the program runs. `name` is what the user reads; without it, the file name is used.

## When it runs

| `when` | Runs |
| - | - |
| `"install"` | on every install, update and repair (the default) |
| `"first_install"` | only the first time, not on updates |
| `"uninstall"` | before the files are removed |

If the step belongs to a [component](/docs/guides/choices-and-components.md), it only runs when that component is installed. This is automatic for files inside a component, or you can set `component = "id"`.

## What happens when it fails

A program succeeds when it exits with code 0, or with one of the codes in `success_codes`. Otherwise:

* During install or update, setup stops, puts everything back and shows **Notes database couldn't be set up (exit code 1)**.
* With `ignore_errors = true`, setup continues.
* During removal, setup always continues, because users must be able to remove your app.

A step that runs too long is ended after 15 minutes. Change that with `timeout_minutes`, up to 120.

## Installing a runtime with your app

Put the installer in your build folder and run it once, with the runtime's own silent options:

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[[run]]
name = "Visual C++ runtime"
file = "redist/vc_redist.x64.exe"
arguments = "/install /quiet /norestart"
success_codes = [0, 1638, 3010]
when = "first_install"
elevated = true
```

Here 1638 means a newer version is already installed, and 3010 means a restart is needed, so both count as success.

## Administrator rights

The runtime installer above needs administrator rights, so the step has `elevated = true`. Windows asks the user once when the step starts. The rest of the install runs normally.

Use `elevated` carefully. In a per-user install, your program sits in a folder that other programs of that user can change. Setup checks the file against a checksum right before asking for rights, but you should still keep elevated steps to well-known, signed installers. `bach check` warns about elevated steps in per-user installs. If your app [installs for every user](/docs/guides/machine-wide-installs.md), the whole setup already runs with administrator rights.

## Arguments and output

`arguments` is passed to your program exactly as written, up to 2000 characters. Nothing in it is replaced, so there's no placeholder for the install folder. The program starts in its own folder, which you can use to find your files.

Whatever the program prints is written to the setup log, which helps when a step fails. See [`[[run]]`](/docs/reference/config/run) for every setting.


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