Skip to main content
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:
bach.toml
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

If the step belongs to a component, 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:
bach.toml
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, 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]] for every setting.