Using NSSM
Mesh
Updated Nov 19, 2025, 03:31 PM
here's a simple powershell that helped me setup beszel-agent as a windows service, nssm.exe needs to be placed in the same directory as the app or installed in path in its own dir:
# Check for administrator privileges
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
try {
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path $scriptPath
Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`"" -Verb RunAs -WorkingDirectory $scriptDir -ErrorAction Stop
exit 0
} catch {
Write-Host "Failed to elevate script: $_"
Read-Host "Press Enter to exit"
exit 1
}
}
try {
Write-Host "Running with admin rights..."
C:\beszel-agent\nssm.exe install beszel-agent "C:\beszel-agent\beszel-agent.exe" --% "-listen ""45876"" -key ""ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOP77rXdtv5yX4yYVy1AIz1ZZ1b1/Xh42Ma3CIbhH0r5"""
C:\beszel-agent\nssm.exe set beszel-agent DisplayName Beszel Agent
C:\beszel-agent\nssm.exe set beszel-agent Description Beszel agent resources monitor
C:\beszel-agent\nssm.exe set beszel-agent Start SERVICE_AUTO_START
C:\beszel-agent\nssm.exe set beszel-agent AppEnvironmentExtra "+EXTRA_FILESYSTEMS=F:,E:"
C:\beszel-agent\nssm.exe start beszel-agent
Write-Host "Agent installed successfully"
Read-Host "Press Enter to exit"
exit 0
}
catch {
Write-Error "An error occurred: $_"
Read-Host "Press Enter to exit"
exit 1
}
To uninstall, use:
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
try {
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path $scriptPath
Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`"" -Verb RunAs -WorkingDirectory $scriptDir -ErrorAction Stop
exit 0
} catch {
Write-Host "Failed to elevate script: $_" Read-Host "Press Enter to exit"
exit 1
}
}
try {Ï
C:\beszel-agent\nssm.exe stop beszel-agent
C:\beszel-agent\nssm.exe remove beszel-agent confirm
Write-Host "Agent uninstalled successfully"
Read-Host "Press Enter to exit"
exit 0
} catch {
Write-Error "An error occurred: $_" Read-Host "Press Enter to exit"
exit 1
}
