# Run it on Windows

The installer sets the program up as a scheduled task of your own user, which starts when you log on and is started again after it fails. It is written to need no administrator rights and no other tool; it was not run by Coronium on Windows, so neither is measured. Calls go to https://supply.coronium.ai. `/kit/index.json` lists the state and the limits of the program and of the installer, and [the files section](/guides/device-files.md) says what each means.

## Needs

- Windows on x86-64 or ARM64, Windows PowerShell, and your own user.
- `agent.env` from [enrolment](/guides/device-enrol.md), in the folder of the downloads. Without it the installer asks for the three values, the secret without showing it.
- Outbound TCP to the relay, no inbound port, and one device per public address.

No installer shows the agreement here, so the signature and the acceptance stored at enrolment are its record.

## Steps

1. Download, check and install, in PowerShell, in a folder of its own. `$ARCH` is `amd64` for x86-64 and `arm64` for ARM64. The block stops at the first line that fails.

```powershell
& {
$ErrorActionPreference = 'Stop'
$SUPPLY = 'https://supply.coronium.ai'
$ARCH = 'amd64'
Invoke-WebRequest -UseBasicParsing "$SUPPLY/kit/SHA256SUMS" -OutFile SHA256SUMS
foreach ($f in "coronium-agent-windows-$ARCH.exe", 'coronium-agent-windows-install.ps1', 'coronium-agent-windows-uninstall.ps1') {
  Invoke-WebRequest -UseBasicParsing "$SUPPLY/kit/$f" -OutFile $f
  $listed = Select-String -Path SHA256SUMS -Pattern ('  ' + [regex]::Escape($f) + '$')
  if (-not $listed -or $listed.Line.Split(' ')[0] -ne (Get-FileHash $f -Algorithm SHA256).Hash.ToLower()) { throw "$f does not match SHA256SUMS" }
}
powershell -NoProfile -ExecutionPolicy Bypass -File .\coronium-agent-windows-install.ps1
}
```

Expect: no error from the checks, then `Installed.` The installer checks the files again, moves `agent.env` into `%LOCALAPPDATA%\CoroniumDevice`, a folder only your user can read, and registers the task `CoroniumDevice`, which holds no setting. The scripts are not signed, so each is started with `-ExecutionPolicy Bypass` after its digest is checked. If refused: `checksum_missing` or `checksum_mismatch` (download again), `wrong_architecture`, `policy_blocks_scripts` (the machine's administrator allows signed scripts only), `bad_settings_file`, `bad_relay`, `bad_device_id` or `bad_secret` (correct `agent.env`), `service_not_started` or `program_not_replaced` (the cause is in the message; after the second, the program installed before runs on). A file a browser downloaded carries a download mark the installer does not handle: download with this block. Nothing is signed yet: the digests are as trustworthy as the site they came from. Safe to repeat: yes, and it keeps the settings.

2. Check.

```powershell
(Get-ScheduledTask -TaskName CoroniumDevice).State
Get-Content -Tail 20 "$env:LOCALAPPDATA\CoroniumDevice\agent.log"
```

Expect: `Running` and `connected to the relay`. A problem is one log line with its cause and its fix, and the agent dials again by itself.

The task belongs to your user: it runs while you are logged on. After a restart it is back once you log on, and not before. Windows starts a failed task again only as often as the task's restart count allows; past it, the task stays down until you log on again. Nothing trims `agent.log`.

## If it is not connected

```powershell
Enable-ScheduledTask -TaskName CoroniumDevice
Start-ScheduledTask -TaskName CoroniumDevice
Get-Content -Tail 5 "$env:LOCALAPPDATA\CoroniumDevice\agent.log"
```

The first two lines start the task again; the third shows why it is not connected, if it is not.

## Update

`/kit/index.json` names the published `version`, and publishing a newer agent does not stop one that is running. To update, run the block of step 1 again in an empty folder, without `agent.env`. The installer checks the new files before it touches anything, keeps the settings that are installed, copies the new program beside the installed one, ends the running task, moves the new program into place and starts it. When a check or the move fails, the installed program stays as it is and runs on.

## Stop and remove

`Stop-ScheduledTask -TaskName CoroniumDevice; Disable-ScheduledTask -TaskName CoroniumDevice` stops sharing and keeps it stopped. To remove the task, the program, its log and `agent.env` with the secret:

```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File "$env:LOCALAPPDATA\CoroniumDevice\uninstall.ps1"
```

It warns, with the process id, about an agent you started yourself, which it does not stop. Removing it does not withdraw the device; [update, stop, remove and withdraw](/guides/device-lifecycle.md) says how.
