# Micro-System - configuration reseau RustDesk. Aucun mot de passe inclus. [CmdletBinding()] param([string]$RustDeskPath, [switch]$CheckOnly, [switch]$Update) $ErrorActionPreference = 'Stop' try { $admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $admin) { throw 'Ouvrez PowerShell en tant qu administrateur, puis relancez la commande.' } if (-not $RustDeskPath) { $candidates = @("$env:ProgramFiles\RustDesk\rustdesk.exe", "${env:ProgramFiles(x86)}\RustDesk\rustdesk.exe") $found = @($candidates | Where-Object { Test-Path -LiteralPath $_ }) if ($found.Count -ne 1) { throw 'RustDesk absent ou plusieurs installations. Utilisez -RustDeskPath avec le chemin exact, ou importez la configuration dans RustDesk.' } $RustDeskPath = $found[0] } if (-not (Test-Path -LiteralPath $RustDeskPath -PathType Leaf)) { throw 'Executable RustDesk introuvable.' } $service = Get-Service -Name RustDesk -ErrorAction SilentlyContinue if (-not $service -or $service.Status -ne 'Running') { throw 'Le service RustDesk doit etre installe et demarre. Pour une version portable, utilisez l import depuis le presse-papiers.' } $expected = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('eyJjdXN0b20tcmVuZGV6dm91cy1zZXJ2ZXIiOiJydXN0ZGVzay5taWNyby1zeXN0ZW0uZnI6MjExMTYiLCJyZWxheS1zZXJ2ZXIiOiJydXN0ZGVzay5taWNyby1zeXN0ZW0uZnI6MjExMTciLCJhcGktc2VydmVyIjoiaHR0cHM6Ly9ydXN0ZGVzay5taWNyby1zeXN0ZW0uZnIiLCJrZXkiOiI5aGk1aWI1SXE4Q2V1d3g5VjI4ZTM2UnZEcDJnd2Q0OU5XbGNEajdRdjBzPSJ9')) | ConvertFrom-Json function Read-Option([string]$Name) { $value = (& $RustDeskPath --option $Name | Out-String).Trim() if ($LASTEXITCODE -ne 0 -or $value -match 'required|disabled|error|failed') { throw "Lecture impossible de $Name. Utilisez l import depuis RustDesk ou mettez le logiciel a jour." } return $value } $before = [ordered]@{} $different = $false foreach ($p in $expected.PSObject.Properties) { $before[$p.Name] = Read-Option $p.Name $ok = $before[$p.Name] -ceq $p.Value Write-Host ("{0}: {1}" -f $p.Name, $(if ($ok) {'conforme'} else {'a corriger'})) if (-not $ok) { $different = $true } } if ($CheckOnly) { if ($different) { exit 2 }; exit 0 } if (-not $different -and -not $Update) { Write-Host 'Configuration deja conforme. Aucun changement.'; exit 0 } $installer = $null if ($Update) { $machineArch = $env:PROCESSOR_ARCHITEW6432 if (-not $machineArch) { $machineArch = $env:PROCESSOR_ARCHITECTURE } $arch = switch ($machineArch.ToUpperInvariant()) { 'ARM64' {'arm64'} 'AMD64' {'x86_64'} 'X86' {'x86'} default {throw 'Architecture non reconnue.'} } $catalog = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('eyJhcm02NCI6eyJ2ZXJzaW9uIjoiMS40LjkiLCJzaGEyNTYiOiJjNzE3YmY1MmZkZDYwMWM1ODQxOWU0NmM1MDMxNzZkZDg3MTg3ZDE3NGViZjhiM2I1ODU0Y2EzODFlOGU5MTQ1IiwidXJsIjoiaHR0cHM6Ly9ydXN0ZGVzay5taWNyby1zeXN0ZW0uZnIvZG93bmxvYWRzLzYifSwieDg2XzY0Ijp7InZlcnNpb24iOiIxLjQuOSIsInNoYTI1NiI6ImVhZWRlYjAwODhlNjg3YmY0NmY3YzQ2YTljNmVhNTQ5M2NlNTFmMzEzNGRmZDZhY2JlZGI0N2I1YjkxMzYyNzQiLCJ1cmwiOiJodHRwczovL3J1c3RkZXNrLm1pY3JvLXN5c3RlbS5mci9kb3dubG9hZHMvMTIifX0=')) | ConvertFrom-Json $installer = $catalog.$arch if (-not $installer) { throw 'Aucun installateur officiel publie pour cette architecture. Utilisez la page de telechargement.' } $current = (& $RustDeskPath --version | Out-String).Trim() if ($current -notmatch '^\d+\.\d+\.\d+$' -or $installer.version -notmatch '^\d+\.\d+\.\d+$') { throw 'Version non comparable : mise a jour manuelle requise pour eviter une regression.' } if ([version]$current -ge [version]$installer.version) { Write-Host 'Version deja egale ou plus recente : aucun remplacement du logiciel.'; $installer = $null } else { Write-Host "Mise a jour prevue : $current vers $($installer.version). La session sera interrompue pendant l installation." } } Write-Warning 'La modification du serveur peut couper cette assistance. Gardez une personne sur place ou un autre acces. Aucun redemarrage automatique ne sera force.' if ((Read-Host 'Tapez APPLIQUER pour corriger les quatre parametres reseau') -cne 'APPLIQUER') { Write-Host 'Annule, aucun changement.'; exit 0 } $folder = Join-Path $env:LOCALAPPDATA ('Micro-System\RustDesk-backup\' + [guid]::NewGuid().ToString()) New-Item -ItemType Directory -Path $folder -Force | Out-Null $before | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $folder 'reseau-avant.json') -Encoding UTF8 $old = @{host=$before['custom-rendezvous-server'];relay=$before['relay-server'];api=$before['api-server'];key=$before['key']} | ConvertTo-Json -Compress $oldCode = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($old)).TrimEnd('=').Replace('+','-').Replace('/','_').ToCharArray() [Array]::Reverse($oldCode) (-join $oldCode) | Set-Content -LiteralPath (Join-Path $folder 'configuration-avant.txt') -Encoding ASCII Write-Host "Sauvegarde des quatre reglages reseau : $folder" if ($installer) { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $setup = Join-Path $folder 'rustdesk-update.exe' Invoke-WebRequest -UseBasicParsing -Uri $installer.url -OutFile $setup if ((Get-FileHash -LiteralPath $setup -Algorithm SHA256).Hash -ine $installer.sha256) { throw 'Empreinte de l installateur incorrecte. Installation annulee.' } if ((Get-AuthenticodeSignature -LiteralPath $setup).Status -ne 'Valid') { throw 'Signature de l installateur non valide. Installation annulee.' } Write-Host 'Installateur telecharge, empreinte et signature verifiees.' $proc = Start-Process -FilePath $setup -ArgumentList '--silent-install' -PassThru -Wait if ($proc.ExitCode -ne 0) { throw 'Installation non confirmee. Conservez la sauvegarde et verifiez le poste.' } Start-Sleep -Seconds 5 $actual = (& $RustDeskPath --version | Out-String).Trim() if ($actual -ne $installer.version) { throw 'La version installee ne correspond pas a la version attendue. Verification manuelle requise.' } (Get-Service RustDesk).WaitForStatus('Running', [TimeSpan]::FromSeconds(30)) } Write-Host 'Application dans 10 secondes...' Start-Sleep -Seconds 10 & $RustDeskPath --config '0nI9MHM2F1NqR0YsdlT5QDZ3dmMwRkdSZzMlhjMWlDe3VXZDhTcJVjYpVTaoljI6ISeltmIsIicm5SblR3c5NXLvJ3Yp1mLrNXZkR3c1J3LvozcwRHdoJiOikGchJCLicTMxEjM6InZu0WZ0NXez1ybyNWat5yazVGZ0NXdyJiOikXYsVmciwiI2ETMxIjOyZmLtVGdzl3ct8mcjlWbus2clRGdzVnciojI0N3boJye' if ($LASTEXITCODE -ne 0) { throw "Echec de la commande. Sauvegarde : $folder" } Start-Sleep -Seconds 2 foreach ($p in $expected.PSObject.Properties) { if ((Read-Option $p.Name) -cne $p.Value) { throw "Configuration non confirmee pour $($p.Name). Ne pas annoncer la reparation. Sauvegarde : $folder" } } Write-Host 'Les quatre reglages reseau ont ete relus et sont conformes. Testez maintenant une connexion Web.' Write-Host 'Si necessaire, relancez RustDesk apres avoir termine cette assistance.' } catch { Write-Error $_ -ErrorAction Continue exit 1 }