# Korvyx FiveM Platform Agent — Windows installer. # Pasted automatically from your korvyx.dev dashboard. Sets $ServerId and # $AgentToken in the parent scope, then pipes this script through `iex`. $ErrorActionPreference = 'Stop' if (-not $ServerId -or -not $AgentToken) { Write-Host "" Write-Host " ERROR: Copy the full one-liner from your dashboard." -ForegroundColor Red Write-Host " (It sets `$ServerId and `$AgentToken before this script runs.)" -ForegroundColor DarkGray Write-Host "" return } $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator ) if (-not $isAdmin) { Write-Host "" Write-Host " ERROR: Run PowerShell as Administrator and try again." -ForegroundColor Red Write-Host " Right-click the Start menu -> 'Windows PowerShell (Admin)'" -ForegroundColor DarkGray Write-Host "" return } $PlatformUrl = "wss://api.korvyx.dev/agent/ws" $InstallDir = "C:\ProgramData\Korvyx" $BinaryUrl = "https://downloads.korvyx.dev/korvyx-agent.exe" $TaskName = "KorvyxAgent" Write-Host "" Write-Host " Korvyx Agent installer" -ForegroundColor Cyan Write-Host " ----------------------" -ForegroundColor DarkGray Write-Host "" # ---- Detect FiveM server-data directory ---- $candidates = @( "C:\fivem\server-data", "C:\FXServer\server-data", "C:\FiveM\server-data", "$env:USERPROFILE\Desktop\fivem\server-data", "$env:USERPROFILE\fivem\server-data", "D:\fivem\server-data", "D:\FXServer\server-data" ) $FiveMServerPath = $null foreach ($p in $candidates) { if (Test-Path $p) { $FiveMServerPath = $p; break } } if ($FiveMServerPath) { Write-Host " Detected FiveM server: $FiveMServerPath" -ForegroundColor Green } else { Write-Host " Could not auto-detect your FiveM server folder." -ForegroundColor Yellow while (-not $FiveMServerPath -or -not (Test-Path $FiveMServerPath)) { $FiveMServerPath = Read-Host " Full path to your FiveM server-data directory" if (-not (Test-Path $FiveMServerPath)) { Write-Host " Not a real folder. Try again." -ForegroundColor Red $FiveMServerPath = $null } } } # ---- Stop any previous install first ---- Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue # ---- Download binary ---- New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null Write-Host " Downloading agent (~42 MB)..." -ForegroundColor DarkGray Invoke-WebRequest -Uri $BinaryUrl -OutFile "$InstallDir\korvyx-agent.exe" -UseBasicParsing # ---- Write config ---- $cfg = [ordered]@{ serverId = $ServerId agentToken = $AgentToken platformUrl = $PlatformUrl fiveMServerPath = $FiveMServerPath rconHost = "127.0.0.1" rconPort = 30120 } $cfg | ConvertTo-Json | Set-Content "$InstallDir\agent.config.json" -Encoding UTF8 # Set AGENT_CONFIG_PATH machine-wide so the binary always finds its config, # even if Windows resets the scheduled task's working directory. [System.Environment]::SetEnvironmentVariable( "AGENT_CONFIG_PATH", "$InstallDir\agent.config.json", "Machine" ) # ---- Register scheduled task (auto-start on boot, restart on crash) ---- Write-Host " Registering Windows service..." -ForegroundColor DarkGray $action = New-ScheduledTaskAction -Execute "$InstallDir\korvyx-agent.exe" -WorkingDirectory $InstallDir $trigger = New-ScheduledTaskTrigger -AtStartup $settings = New-ScheduledTaskSettingsSet ` -AllowStartIfOnBatteries ` -DontStopIfGoingOnBatteries ` -RestartCount 999 ` -RestartInterval (New-TimeSpan -Minutes 1) ` -ExecutionTimeLimit (New-TimeSpan -Seconds 0) $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest Register-ScheduledTask ` -TaskName $TaskName ` -Action $action ` -Trigger $trigger ` -Settings $settings ` -Principal $principal ` -Description "Korvyx FiveM Platform Agent" | Out-Null Start-ScheduledTask -TaskName $TaskName Start-Sleep -Seconds 4 $state = (Get-ScheduledTask -TaskName $TaskName).State Write-Host "" Write-Host " Installed." -ForegroundColor Green Write-Host " Status: $state" Write-Host " Path: $InstallDir" Write-Host "" Write-Host " Open your korvyx.dev dashboard — agent will appear online in a few seconds." -ForegroundColor Cyan Write-Host "" Write-Host " Manage later:" -ForegroundColor DarkGray Write-Host " Restart: Stop-ScheduledTask $TaskName; Start-ScheduledTask $TaskName" Write-Host " Uninstall: Unregister-ScheduledTask $TaskName -Confirm:`$false; rm '$InstallDir' -Recurse" Write-Host ""