zrok/docs/guides/agent/windows-service/index.mdx
Michael Quigley 257b51a87a
docs (#916)
2025-03-26 12:46:46 -04:00

40 lines
1.7 KiB
Plaintext

---
title: Configuring a Windows Service
---
In Windows environments, it can be useful to run the zrok Agent as a service, allowing it to automatically restart with your system.
Support for running the zrok Agent as a Windows service is handled through a third party utility, `nssm`, which is available here:
[https://nssm.cc/download](https://nssm.cc/download)
Give the `nssm` documentation a quick review, here:
[https://nssm.cc/usage](https://nssm.cc/usage)
You'll want to install both the `zrok.exe` and `nssm.exe` in a convenient protected location. In this example, we'll put them in `C:\Program Files\zrok`, as `C:\Program Files\zrok\zrok.exe` and `C:\Program Files\zrok\nssm.exe`.
![C:\\Program Files\\zrok](images/program-files.png)
We're going to use a command prompt to install and configure our Agent service. Open a new command prompt and `cd "\Program Files\zrok"`:
![Empty Command Prompt](images/empty-command-prompt.png)
## Enabling the Service Environment
On Windows, the `USERPROFILE` environment variable controls the "home" where zrok will look for the enabled environment. When running as a service on Windows, the process will be running as the `LocalSystem` user, which uses the directory `C:\Windows\System32\config\systemprofile` directory as the user's "home" directory.
We're going to want to enable a zrok environment for our new Agent service in this directory. First, we'll run:
```cmd
C:\Program Files\zrok>set USERPROFILE=c:\Windows\System32\config\systemprofile
```
And with that environment variable set, we'll use the `zrok enable` command to enable an environment for our new Agent service:
```cmd
C:\Program Files\zrok>zrok enable <accountToken>
```
![Enabling the Service Environment](images/enable.png)