#Requires -RunAsAdministrator <# .SYNOPSIS RustDesk Silent Install + Konfiguration für privaten Server .DESCRIPTION Installiert RustDesk und konfiguriert automatisch den privaten HBBS/HBBR-Server (rd.wende.it) inkl. Public Key. Geeignet für Intune (Win32) und SCCM Deployment. .NOTES Server: rd.wende.it Public Key: aPiGBXPfnyXtDCN8tiut2IziZeadbmocOdJEduzKtoQ #> # ============================================================ # Konfiguration # ============================================================ $RustDeskVersion = "1.3.8" $InstallerUrl = "https://github.com/rustdesk/rustdesk/releases/download/$RustDeskVersion/rustdesk-$RustDeskVersion-x86_64.exe" $InstallerPath = "$env:TEMP\rustdesk-setup.exe" $InstallDir = "$env:ProgramFiles\RustDesk" $ConfigDir = "$env:ProgramData\RustDesk" $HbbsServer = "rd.wende.it" $HbbrServer = "rd.wende.it" # HBBR läuft auf demselben Host $PublicKey = "aPiGBXPfnyXtDCN8tiut2IziZeadbmocOdJEduzKtoQ" # ============================================================ # Logging # ============================================================ $LogFile = "$env:ProgramData\Microsoft\IntuneManagementExtension\Logs\Install-RustDesk.log" function Write-Log { param([string]$Message) $ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss" "$ts $Message" | Tee-Object -FilePath $LogFile -Append | Write-Output } Write-Log "=== RustDesk Deployment gestartet ===" # ============================================================ # 1. Download # ============================================================ if (-not (Test-Path $InstallerPath)) { Write-Log "Download: $InstallerUrl" try { Invoke-WebRequest -Uri $InstallerUrl -OutFile $InstallerPath -UseBasicParsing Write-Log "Download abgeschlossen." } catch { Write-Log "FEHLER beim Download: $_" exit 1 } } else { Write-Log "Installer bereits vorhanden, überspringe Download." } # ============================================================ # 2. Silent Install # ============================================================ Write-Log "Starte Silent-Installation..." $proc = Start-Process -FilePath $InstallerPath -ArgumentList "--silent-install" -Wait -PassThru if ($proc.ExitCode -notin @(0, 3010)) { Write-Log "FEHLER: Installer ExitCode $($proc.ExitCode)" exit $proc.ExitCode } Write-Log "Installation abgeschlossen (ExitCode: $($proc.ExitCode))." # ============================================================ # 3. Warte auf rustdesk.exe # ============================================================ $RustDeskExe = "$InstallDir\rustdesk.exe" $timeout = 30 $elapsed = 0 while (-not (Test-Path $RustDeskExe) -and $elapsed -lt $timeout) { Start-Sleep -Seconds 2 $elapsed += 2 } if (-not (Test-Path $RustDeskExe)) { Write-Log "FEHLER: rustdesk.exe nicht gefunden nach $timeout Sekunden." exit 1 } # ============================================================ # 4. RustDesk kurz starten (erzeugt Config-Dateien) # ============================================================ Write-Log "Starte RustDesk einmalig zur Config-Initialisierung..." Start-Process -FilePath $RustDeskExe -ArgumentList "--service" -NoNewWindow Start-Sleep -Seconds 5 Stop-Process -Name "rustdesk" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 # ============================================================ # 5. Konfiguration schreiben (RustDesk2.toml) # ============================================================ if (-not (Test-Path $ConfigDir)) { New-Item -ItemType Directory -Path $ConfigDir -Force | Out-Null } $RustDesk2Toml = @" rendezvous_server = '$HbbsServer' nat_type = 1 serial = 0 [options] custom-rendezvous-server = '$HbbsServer' relay-server = '$HbbrServer' api-server = 'https://$HbbsServer' key = '$PublicKey' direct-server = 'Y' direct-access-port = '21118' "@ $TomlPath = "$ConfigDir\RustDesk2.toml" $RustDesk2Toml | Set-Content -Path $TomlPath -Encoding UTF8 -Force Write-Log "Konfiguration geschrieben: $TomlPath" # ============================================================ # 6. Konfiguration auch im User-Profil hinterlegen (All Users) # ============================================================ # RustDesk liest je nach Version aus AppData – sicherstellen dass # alle bestehenden Profile ebenfalls die Config erhalten $UserProfiles = Get-ChildItem "C:\Users" -Directory | Where-Object { $_.Name -notmatch '^(Public|Default.*|All Users)$' } foreach ($profile in $UserProfiles) { $userConfigDir = "$($profile.FullName)\AppData\Roaming\RustDesk\config" if (-not (Test-Path $userConfigDir)) { New-Item -ItemType Directory -Path $userConfigDir -Force | Out-Null } $RustDesk2Toml | Set-Content -Path "$userConfigDir\RustDesk2.toml" -Encoding UTF8 -Force Write-Log "User-Config geschrieben: $userConfigDir" } # Default-Profil (für neue User) $defaultConfigDir = "C:\Users\Default\AppData\Roaming\RustDesk\config" if (-not (Test-Path $defaultConfigDir)) { New-Item -ItemType Directory -Path $defaultConfigDir -Force | Out-Null } $RustDesk2Toml | Set-Content -Path "$defaultConfigDir\RustDesk2.toml" -Encoding UTF8 -Force Write-Log "Default-Profil Config geschrieben." # ============================================================ # 7. RustDesk-Dienst starten # ============================================================ Write-Log "Starte RustDesk-Dienst..." Start-Process -FilePath $RustDeskExe -ArgumentList "--install-service" -Wait -NoNewWindow -ErrorAction SilentlyContinue Start-Sleep -Seconds 3 $svc = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue if ($svc) { Start-Service -Name "RustDesk" -ErrorAction SilentlyContinue Write-Log "RustDesk-Dienst Status: $($svc.Status)" } else { Write-Log "WARNUNG: RustDesk-Dienst nicht gefunden, starte als Prozess." Start-Process -FilePath $RustDeskExe -NoNewWindow } # ============================================================ # Aufräumen # ============================================================ Remove-Item -Path $InstallerPath -Force -ErrorAction SilentlyContinue Write-Log "=== RustDesk Deployment abgeschlossen ===" exit 0