# LaDolce Print Agent — installer for the office Windows PC # # Run in PowerShell **as Administrator** from the folder containing agent.ps1: # powershell -ExecutionPolicy Bypass -File .\install.ps1 # # It will: # 1. copy the agent to C:\ProgramData\LaDolcePrint # 2. download SumatraPDF (silent PDF printing) # 3. ask for the agent token and which printer to use # 4. register a startup task "LaDolce Print Agent" (runs as SYSTEM, restarts on failure) $ErrorActionPreference = 'Stop' $Home_ = 'C:\ProgramData\LaDolcePrint' $Server = 'https://print.ladolcecorp.com' $SumatraZip = 'https://www.sumatrapdfreader.org/dl/rel/3.5.2/SumatraPDF-3.5.2-64.zip' $TaskName = 'LaDolce Print Agent' $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { throw 'Please run PowerShell as Administrator.' } [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # 1. Folder (Administrators + SYSTEM only — it holds the agent token) New-Item $Home_ -ItemType Directory -Force | Out-Null icacls $Home_ /inheritance:r /grant:r 'Administrators:(OI)(CI)F' 'SYSTEM:(OI)(CI)F' | Out-Null Copy-Item (Join-Path $PSScriptRoot 'agent.ps1') $Home_ -Force # 2. SumatraPDF if (-not (Test-Path "$Home_\SumatraPDF.exe")) { Write-Host 'Downloading SumatraPDF...' $zip = Join-Path $env:TEMP 'sumatra.zip' Invoke-WebRequest $SumatraZip -OutFile $zip -UseBasicParsing $tmp = Join-Path $env:TEMP 'sumatra' Expand-Archive $zip $tmp -Force Get-ChildItem $tmp -Filter 'SumatraPDF*.exe' | Select-Object -First 1 | Copy-Item -Destination "$Home_\SumatraPDF.exe" -Force Remove-Item $zip, $tmp -Recurse -Force } # 3. Config $token = Read-Host 'Agent token (from the server install output)' if (-not $token) { throw 'Agent token is required.' } $printers = @(Get-Printer | Select-Object -ExpandProperty Name) $default = $printers | Where-Object { $_ -like '*EPSON*L3210*' } | Select-Object -First 1 Write-Host "`nPrinters on this PC:" for ($i = 0; $i -lt $printers.Count; $i++) { Write-Host " [$i] $($printers[$i])" } $pick = Read-Host "Printer number to use$(if ($default) { " (Enter = $default)" })" $printer = if ($pick -match '^\d+$') { $printers[[int]$pick] } else { $default } if (-not $printer) { throw 'No printer selected.' } @{ server = $Server; token = $token.Trim(); printer = $printer } | ConvertTo-Json | Set-Content "$Home_\config.json" -Encoding UTF8 # Quick connectivity/token check try { Invoke-RestMethod "$Server/agent/next.php" -Headers @{ Authorization = "Bearer $($token.Trim())" } -TimeoutSec 45 | Out-Null Write-Host 'Server connection OK.' } catch { throw "Could not connect with that token: $($_.Exception.Message)" } # 4. Startup task $action = New-ScheduledTaskAction -Execute 'powershell.exe' ` -Argument "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$Home_\agent.ps1`"" $trigger = New-ScheduledTaskTrigger -AtStartup $principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` -ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) ` -StartWhenAvailable Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings | Out-Null Start-ScheduledTask -TaskName $TaskName Write-Host "`nInstalled. '$TaskName' is running and will start with Windows." Write-Host "Printing to: $printer" Write-Host "Log file: $Home_\agent.log"