# JARVIS Agent Installer — Windows (PowerShell) # Run as Administrator: # Set-ExecutionPolicy Bypass -Scope Process # .\install-windows.ps1 -JarvisUrl https://jarvis.orbishosting.com -Key YOUR_KEY # Or one-liner (from PowerShell as Admin): # irm https://jarvis.orbishosting.com/agent/install-windows.ps1 | iex param( [string]$JarvisUrl = "https://jarvis.orbishosting.com", [string]$Key = "", [string]$AgentName = $env:COMPUTERNAME.ToLower() ) $ErrorActionPreference = "Stop" $InstallDir = "C:\ProgramData\jarvis-agent" $AgentScript = "$InstallDir\jarvis-agent.py" $ConfigFile = "$InstallDir\config.json" $TaskName = "JARVIS-Agent" Write-Host "" Write-Host " ====================================" -ForegroundColor Cyan Write-Host " JARVIS Agent Installer v2.2 " -ForegroundColor Cyan Write-Host " ====================================" -ForegroundColor Cyan Write-Host "" # ── Require admin ───────────────────────────────────────────────────────────── if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Error "Run PowerShell as Administrator and try again." } # ── Prompt if not provided ──────────────────────────────────────────────────── $JarvisUrl = $JarvisUrl.TrimEnd("/") if (-not $Key) { $Key = Read-Host "Enter registration key" } # ── Find Python 3 ───────────────────────────────────────────────────────────── Write-Host "Checking Python 3..." -NoNewline $python = $null $searchPaths = @( "python", "python3", "py", "$env:LOCALAPPDATA\Programs\Python\Python312\python.exe", "$env:LOCALAPPDATA\Programs\Python\Python311\python.exe", "$env:LOCALAPPDATA\Programs\Python\Python310\python.exe", "C:\Python312\python.exe", "C:\Python311\python.exe" ) foreach ($p in $searchPaths) { try { $ver = & $p --version 2>&1 if ("$ver" -match "Python 3") { $python = $p; break } } catch {} } if (-not $python) { Write-Host " not found." -ForegroundColor Yellow Write-Host "Installing Python 3.12 via winget..." -ForegroundColor Yellow try { winget install Python.Python.3.12 --silent --accept-package-agreements --accept-source-agreements $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User") foreach ($p in @("python","python3")) { try { $ver = & $p --version 2>&1; if ("$ver" -match "Python 3") { $python = $p; break } } catch {} } } catch {} } if (-not $python) { Write-Error "Python 3 not found. Install from https://python.org then re-run." } # Resolve full path for task scheduler (PS 5.1 compatible — no ?. operator) $_pyCmd = Get-Command $python -ErrorAction SilentlyContinue $pythonPath = if ($_pyCmd) { $_pyCmd.Source } else { $null } if (-not $pythonPath -or -not (Test-Path $pythonPath)) { foreach ($p in @("$env:LOCALAPPDATA\Programs\Python\Python312\python.exe", "$env:LOCALAPPDATA\Programs\Python\Python311\python.exe", "C:\Python312\python.exe")) { if (Test-Path $p) { $pythonPath = $p; break } } } if (-not $pythonPath) { $pythonPath = $python } Write-Host " $pythonPath" -ForegroundColor Green # ── Create install directory ────────────────────────────────────────────────── New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null Write-Host "Install dir: $InstallDir" # ── Download Windows agent script ───────────────────────────────────────────── Write-Host "Downloading jarvis-agent-windows.py..." -NoNewline try { [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } $wc = New-Object System.Net.WebClient $wc.Headers.Add("User-Agent", "JARVIS-Installer/1.0") $wc.DownloadFile("$JarvisUrl/agent/jarvis-agent-windows.py", $AgentScript) Write-Host " done." -ForegroundColor Green } catch { Write-Error "Download failed from $JarvisUrl/agent/jarvis-agent-windows.py`nError: $_" } # ── Write config ────────────────────────────────────────────────────────────── $agentId = "${AgentName}_windows" $config = [ordered]@{ jarvis_url = $JarvisUrl host_header = "" ssl_verify = $true registration_key = $Key agent_type = "windows" hostname = $AgentName agent_id = $agentId poll_interval = 30 heartbeat_every = 10 watch_services = @("WinDefend", "Spooler") } | ConvertTo-Json -Depth 3 [System.IO.File]::WriteAllText($ConfigFile, $config, [System.Text.UTF8Encoding]::new($false)) Write-Host "Config: $ConfigFile" # ── Register scheduled task ─────────────────────────────────────────────────── try { Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue } catch {} $action = New-ScheduledTaskAction -Execute "`"$pythonPath`"" ` -Argument "`"$AgentScript`"" -WorkingDirectory $InstallDir $trigger = New-ScheduledTaskTrigger -AtStartup $settings = New-ScheduledTaskSettingsSet ` -ExecutionTimeLimit (New-TimeSpan -Seconds 0) ` -RestartCount 10 -RestartInterval (New-TimeSpan -Minutes 1) ` -StartWhenAvailable -MultipleInstances IgnoreNew # Run as current user (not SYSTEM) so per-user Python install is accessible $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $principal = New-ScheduledTaskPrincipal -UserId $currentUser -LogonType Interactive -RunLevel Highest Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger ` -Settings $settings -Principal $principal ` -Description "JARVIS AI System Monitoring Agent" -Force | Out-Null Write-Host "Scheduled task '$TaskName' registered." -ForegroundColor Green # ── Start now ───────────────────────────────────────────────────────────────── Write-Host "Starting agent..." -NoNewline Start-ScheduledTask -TaskName $TaskName Start-Sleep -Seconds 3 $state = (Get-ScheduledTask -TaskName $TaskName).State Write-Host " $state" -ForegroundColor $(if ($state -eq "Running") {"Green"} else {"Yellow"}) Write-Host "" Write-Host " Installation complete!" -ForegroundColor Green Write-Host " Machine : $AgentName ($agentId)" -ForegroundColor White Write-Host " JARVIS : $JarvisUrl" -ForegroundColor White Write-Host " Logs : $InstallDir\jarvis-agent.log" -ForegroundColor White Write-Host "" Write-Host " Useful commands:" -ForegroundColor Gray Write-Host " Get-Content '$InstallDir\jarvis-agent.log' -Tail 20 -Wait" -ForegroundColor Gray Write-Host " Stop-ScheduledTask -TaskName '$TaskName'" -ForegroundColor Gray Write-Host " Start-ScheduledTask -TaskName '$TaskName'" -ForegroundColor Gray Write-Host " Unregister-ScheduledTask -TaskName '$TaskName' -Confirm:`$false" -ForegroundColor Gray Write-Host ""