param( [string]$Server = 'rustdesk.alencindrak.from.hr', [string]$ApiServer = 'https://rustdesk.alencindrak.from.hr', [string]$PublicKey = 'v8iCdt8MxgaXKZW8GUFXGaJJC72WQggO4S+mSgohJ9k=' ) $ErrorActionPreference = 'Stop' try { $rdIdentity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() if (-not $rdIdentity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Pokrenite installer kao administrator.' } $rdExe = Join-Path $env:ProgramFiles 'RustDesk\RustDesk.exe' if (-not (Test-Path -LiteralPath $rdExe)) { throw 'RustDesk nije instaliran.' } $rdService = Get-Service -Name RustDesk -ErrorAction Stop if ($rdService.Status -ne 'Running') { Start-Service -Name RustDesk } $rdService.WaitForStatus('Running', [TimeSpan]::FromSeconds(20)) $rdOptions = [ordered]@{ 'key' = $PublicKey 'custom-rendezvous-server' = $Server 'relay-server' = "${Server}:21117" 'api-server' = $ApiServer } foreach ($rdOption in $rdOptions.GetEnumerator()) { $rdVerified = $false for ($rdAttempt = 0; $rdAttempt -lt 6; $rdAttempt++) { & $rdExe --option $rdOption.Key $rdOption.Value | Out-Null Start-Sleep -Milliseconds 750 $rdActual = (& $rdExe --option $rdOption.Key | Out-String).Trim() if ($rdActual -eq $rdOption.Value) { $rdVerified = $true; break } } if (-not $rdVerified) { throw "Postavka '$($rdOption.Key)' nije potvrdena. Ponovno pokrenite installer." } } Write-Output 'RustDesk je podesen. Prijavite se u aplikaciji i otvorite Accessible devices.' exit 0 } catch { Write-Error $_.Exception.Message -ErrorAction Continue exit 1 }