# ============================== # RUSTDESK ENTERPRISE DEPLOY # ============================== $ErrorActionPreference = "Stop" # ---- CONFIG ---- $SERVER_IP = "82.67.42.150" $KEY = "OIslhzHmGvursM8Hz6O17Y7Wn+F75vrGvvC8p2+ZoUo=" $ADMIN_URL = "https://rustdesk-admin.healthybyte.fr" $API_KEY = "qKEuLOexQjE6DeRtsVIJTVmeCzySjeb6U+8SEAk0bSc=" $VERSION = "1.4.6" # ---- UTF-8 FIX ---- [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8 chcp 65001 | Out-Null # ---- PASSWORD ---- function New-RandomPassword { $chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!@#%&*' -join (1..20 | ForEach-Object { $chars[(Get-Random -Max $chars.Length)] }) } $RD_PASSWORD = New-RandomPassword # ---- DOWNLOAD MSI (robuste + stable) ---- Write-Host "Download RustDesk..." -ForegroundColor Cyan $msiUrl = "https://github.com/rustdesk/rustdesk/releases/download/$VERSION/rustdesk-$VERSION-x86_64.msi" $msi = "$env:TEMP\rustdesk.msi" Invoke-WebRequest -Uri $msiUrl -OutFile $msi -UseBasicParsing # ---- SILENT INSTALL (ENTERPRISE MODE) ---- Write-Host "Silent install..." -ForegroundColor Cyan Start-Process "msiexec.exe" -ArgumentList "/i `"$msi`" /qn /norestart" -Wait # ---- WAIT SERVICE READY ---- Write-Host "Waiting RustDesk service..." -ForegroundColor Cyan Start-Sleep -Seconds 10 $rdProcess = $null for ($i=0; $i -lt 20; $i++) { $rdProcess = Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Name -match "rustdesk" } if ($rdProcess) { break } Start-Sleep -Seconds 2 } # ---- CONFIG PATH ---- $configDir = "$env:APPDATA\RustDesk" $configFile = "$configDir\config.toml" if (!(Test-Path $configDir)) { New-Item -ItemType Directory -Path $configDir -Force | Out-Null } # ---- APPLY PASSWORD (stable format) ---- $encodedPwd = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($RD_PASSWORD)) @" password = "$encodedPwd" "@ | Set-Content -Path $configFile -Encoding UTF8 -Force # ---- GET RUSTDESK ID (enterprise safe method) ---- function Get-RustDeskId { # 1. ATTEMPT: registry (selon versions Windows install) $regPaths = @( "HKCU:\Software\RustDesk", "HKLM:\Software\RustDesk" ) foreach ($r in $regPaths) { try { $val = Get-ItemProperty -Path $r -Name "id" -ErrorAction SilentlyContinue if ($val.id) { return $val.id } } catch {} } # 2. ATTEMPT: memory/service output (fallback réaliste) $proc = Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "rustdesk*" } if ($proc) { return $null } return $null } Write-Host "Waiting RustDesk ID..." -ForegroundColor Cyan $id = $null for ($i = 0; $i -lt 30; $i++) { $id = Get-RustDeskId if ($id -match '^\d{6,12}$') { break } Start-Sleep -Seconds 2 } if (-not $id) { Write-Host "ID introuvable automatiquement" -ForegroundColor Yellow $id = Read-Host "Entrer l'ID affiché dans RustDesk (obligatoire)" } # ---- LOCAL INFO ---- $ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike "127.*" -and $_.IPAddress -notlike "169.*" } | Select-Object -First 1 -ExpandProperty IPAddress) $os = (Get-CimInstance Win32_OperatingSystem).Caption # ---- REGISTER API (retry enterprise) ---- $body = @{ hostname = $env:COMPUTERNAME rustdesk_id = $id password = $RD_PASSWORD ip = $ip os = $os } | ConvertTo-Json -Depth 3 Write-Host "Registering..." -ForegroundColor Cyan $maxRetry = 5 $success = $false for ($i=0; $i -lt $maxRetry; $i++) { try { Invoke-RestMethod ` -Uri "$ADMIN_URL/api/register" ` -Method POST ` -Headers @{ "x-api-key" = $API_KEY } ` -ContentType "application/json" ` -Body $body | Out-Null $success = $true break } catch { Start-Sleep -Seconds 3 } } # ---- OUTPUT ---- if ($success) { Write-Host "OK - Machine enregistrée" -ForegroundColor Green } else { Write-Host "API KO - RustDesk installé localement OK" -ForegroundColor Yellow } Write-Host "" Write-Host "============================" Write-Host "ID : $id" Write-Host "PASS : $RD_PASSWORD" Write-Host "============================" Read-Host "Terminé"