$ErrorActionPreference = "SilentlyContinue" $HOST_ADDR = "remote.iconic.io.vn" $PUB_KEY = "0MqAcRTYZxmnVw6pJs3v1WnjdDvMx0O0mDOERGBb0+c=" $CFG_STR = "host=$HOST_ADDR,key=$PUB_KEY" # Ensure Administrator privileges if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "Requesting administrative privileges..." -ForegroundColor Yellow Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"irm https://remote.iconic.io.vn | iex`"" exit } Write-Host "Checking RustDesk installation..." -ForegroundColor Cyan # 1. Check current installed version $installedVer = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk\" -ErrorAction SilentlyContinue).DisplayVersion $InstallPath = "$env:ProgramFiles\RustDesk\rustdesk.exe" # 2. Query latest release from GitHub $needsInstallOrUpdate = $false $downloadUrl = $null $latestVer = $null try { $rel = Invoke-RestMethod -Uri "https://api.github.com/repos/rustdesk/rustdesk/releases/latest" -Headers @{"User-Agent"="RustDeskInstaller"} -UseBasicParsing -TimeoutSec 10 $latestVer = $rel.tag_name $asset = $rel.assets | Where-Object { $_.name -match "x86_64\.exe$" } | Select-Object -First 1 if ($asset) { $downloadUrl = $asset.browser_download_url } } catch {} if (-not (Test-Path $InstallPath)) { $needsInstallOrUpdate = $true } elseif ($latestVer -and $installedVer -and ($installedVer -ne $latestVer)) { Write-Host "Update available: $installedVer -> $latestVer" -ForegroundColor Yellow $needsInstallOrUpdate = $true } # 3. Perform install or update if needed if ($needsInstallOrUpdate) { if (-not $downloadUrl) { $downloadUrl = "https://github.com/rustdesk/rustdesk/releases/download/1.4.9/rustdesk-1.4.9-x86_64.exe" } Write-Host "Downloading RustDesk $latestVer..." $Installer = "$env:TEMP\rustdesk-setup.exe" Invoke-WebRequest -Uri $downloadUrl -OutFile $Installer -UseBasicParsing Write-Host "Stopping running instances..." Stop-Process -Name "rustdesk" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 1 Write-Host "Installing RustDesk..." $proc = Start-Process $Installer -ArgumentList "--silent-install" -PassThru if ($proc) { $proc.WaitForExit(30000) | Out-Null } Start-Sleep -Seconds 3 Remove-Item $Installer -Force -ErrorAction SilentlyContinue } else { Write-Host "RustDesk is already installed ($installedVer)." -ForegroundColor Green } # 4. Ensure system service is running $ServiceName = "Rustdesk" $service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue if ($null -eq $service) { if (Test-Path $InstallPath) { Start-Process $InstallPath -ArgumentList "--install-service" -Wait Start-Sleep -Seconds 3 $service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue } } if ($service -and $service.Status -ne "Running") { Start-Service -Name $ServiceName -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 } # 5. Apply server configuration Write-Host "Configuring server and maximum quality settings..." if (Test-Path $InstallPath) { & $InstallPath --config $CFG_STR } # 6. Inject Maximum Quality & Performance Settings (YUV444, 60FPS, GPU Encode, Direct3D, Best Quality) $qualitySettings = @{ "custom-rendezvous-server" = "'$HOST_ADDR'" "relay-server" = "'$HOST_ADDR'" "key" = "'$PUB_KEY'" "i444" = "'Y'" "image_quality" = "'best'" "custom-fps" = "'60'" "enable-hwcodec" = "'Y'" "enable-directx-capture" = "'Y'" "allow-d3d-render" = "'Y'" "view_style" = "'original'" "codec-preference" = "'auto'" } $cfgDirs = @( "$env:APPDATA\RustDesk\config", "$env:WINDIR\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config" ) foreach ($dir in $cfgDirs) { if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null } $cfgPath = "$dir\RustDesk2.toml" $lines = @() if (Test-Path $cfgPath) { $lines = Get-Content $cfgPath | Where-Object { $l = $_ $match = $false foreach ($k in $qualitySettings.Keys) { if ($l -match "^\s*$k\s*=") { $match = $true; break } } -not $match } } if (-not ($lines -match "^\s*\[options\]")) { $lines += "[options]" } $final = @() foreach ($line in $lines) { $final += $line if ($line -match "^\s*\[options\]") { foreach ($k in $qualitySettings.Keys) { $v = $qualitySettings[$k] $final += "$k = $v" } } } $final | Set-Content -Path $cfgPath -Encoding UTF8 -Force } # 7. Configure Default Peer Quality & Sync Existing Peers $defaultToml = "$env:APPDATA\RustDesk\config\RustDesk_default.toml" $defaultContent = "view_style = 'original'`nscroll_style = 'scrollauto'`nedge_scroll_edge_thickness = 100`nimage_quality = 'best'`ncustom_image_quality = [100]`n`n[options]`ncustom-fps = '60'`ni444 = 'Y'`ncodec-preference = 'auto'" Set-Content -Path $defaultToml -Value $defaultContent -Encoding UTF8 -Force $peersDir = "$env:APPDATA\RustDesk\config\peers" if (Test-Path $peersDir) { Get-ChildItem -Path $peersDir -Filter "*.toml" | ForEach-Object { $p = $_.FullName $lines = Get-Content $p $newLines = @() foreach ($l in $lines) { if ($l -match "^\s*view_style\s*=") { $newLines += "view_style = 'original'" } elseif ($l -match "^\s*custom_image_quality\s*=") { $newLines += "custom_image_quality = [100]" } elseif ($l -match "^\s*image_quality\s*=") { $newLines += "image_quality = 'best'" } elseif ($l -match "^\s*custom-fps\s*=") { $newLines += "custom-fps = '60'" } elseif ($l -match "^\s*i444\s*=") { $newLines += "i444 = 'Y'" } else { $newLines += $l } } $newLines | Set-Content -Path $p -Encoding UTF8 -Force } } # 8. Restart application Stop-Process -Name "rustdesk" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 1 if (Test-Path $InstallPath) { Start-Process $InstallPath } Write-Host "RustDesk configured with maximum visual quality (YUV 4:4:4, 60 FPS, HW Accel)." -ForegroundColor Green