Skip to content

Instantly share code, notes, and snippets.

@michele-tn
Last active November 10, 2025 17:21
Show Gist options
  • Select an option

  • Save michele-tn/8a824d6257147718fd8384da0fa13f7a to your computer and use it in GitHub Desktop.

Select an option

Save michele-tn/8a824d6257147718fd8384da0fa13f7a to your computer and use it in GitHub Desktop.
<#
RustDesk Portable (x64) Auto Downloader & Configurator
-----------------------------------------------------
• Downloads the latest available RustDesk Windows x64 portable client from GitHub
• No installation (single .exe)
• Automatically sets:
- ID server
- Key
(Relay e API non impostati)
• Creates and updates a download log
• Launches RustDesk ready to use
Config path usato (utente corrente):
%AppData%\RustDesk\config\RustDesk2.toml
#>
param(
[string]$ServerIP = "192.168.1.100", # ID server (hbbs)
[string]$Key = "MY_PUBLIC_KEY" # Contenuto id_ed25519.pub (stringa completa)
)
# ----------------- ENVIRONMENT & TLS -----------------
try {
[Net.ServicePointManager]::SecurityProtocol = `
[Net.ServicePointManager]::SecurityProtocol -bor `
[Net.SecurityProtocolType]::Tls12
} catch { }
$ErrorActionPreference = "Stop"
# ----------------- SCRIPT ROOT -----------------
if ($PSScriptRoot -and (Test-Path $PSScriptRoot)) {
$scriptRoot = $PSScriptRoot
} elseif ($MyInvocation.MyCommand.Path) {
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
} else {
$scriptRoot = Get-Location
}
# ----------------- PATHS -----------------
$baseFolder = Join-Path $scriptRoot "RustDeskPortable"
$exePath = Join-Path $baseFolder "rustdesk.exe"
$logPath = Join-Path $baseFolder "update.log"
# Config ufficiale RustDesk per l'utente corrente
$rustdeskConfigDir = Join-Path ([Environment]::GetFolderPath("ApplicationData")) "RustDesk\config"
$configPath = Join-Path $rustdeskConfigDir "RustDesk2.toml"
# Create folders
New-Item -ItemType Directory -Path $baseFolder -Force | Out-Null
New-Item -ItemType Directory -Path $rustdeskConfigDir -Force | Out-Null
$headers = @{ "User-Agent" = "PowerShell-RustDeskPortable" }
Write-Host "===> Fetching latest RustDesk tag from GitHub..." -ForegroundColor Cyan
# ----------------- FETCH LATEST TAG -----------------
$tagsUrl = "https://api.github.com/repos/rustdesk/rustdesk/tags"
try {
$tags = Invoke-RestMethod -Uri $tagsUrl -Headers $headers
} catch {
Write-Error "❌ Failed to retrieve tags from GitHub: $($_.Exception.Message)"
exit 1
}
if (-not $tags) {
Write-Error "❌ No tags found on GitHub repository rustdesk/rustdesk."
exit 1
}
$latestTag = $tags[0].name
Write-Host "Latest tag detected: $latestTag" -ForegroundColor Green
# ----------------- FETCH RELEASE BY TAG -----------------
$releaseUrl = "https://api.github.com/repos/rustdesk/rustdesk/releases/tags/$latestTag"
try {
$release = Invoke-RestMethod -Uri $releaseUrl -Headers $headers
} catch {
Write-Error "❌ Failed to retrieve release for tag '$latestTag': $($_.Exception.Message)"
exit 1
}
if (-not $release.assets) {
Write-Error "❌ No assets found in release '$latestTag'."
exit 1
}
# ----------------- SELECT PORTABLE X64 CLIENT -----------------
# Windows x64 portable .exe (no server, no MSI)
$asset = $release.assets | Where-Object {
$_.name -match "^rustdesk-.*x86_64.*\.exe$" -and
$_.name -notmatch "server" -and
$_.name -notmatch "\.msi$"
} | Select-Object -First 1
if (-not $asset) {
Write-Error "❌ No suitable Windows x64 portable executable found for tag '$latestTag'."
exit 1
}
$downloadUrl = $asset.browser_download_url
Write-Host "Download URL: $downloadUrl" -ForegroundColor Cyan
# ----------------- DOWNLOAD EXECUTABLE -----------------
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $exePath -Headers $headers
} catch {
Write-Error "❌ Error while downloading RustDesk executable: $($_.Exception.Message)"
exit 1
}
if (!(Test-Path $exePath)) {
Write-Error "❌ Download failed: file not found at '$exePath'."
exit 1
}
Write-Host "✅ Downloaded RustDesk executable to: $exePath" -ForegroundColor Green
# ----------------- WRITE RustDesk2.toml CONFIG -----------------
# Formato testato: ID server + Key
# Questo deve riempire i campi "ID server" e "Key" nella GUI.
# Rimuovi eventuale config precedente per evitare merge strani
if (Test-Path $configPath) {
Remove-Item $configPath -Force -ErrorAction SilentlyContinue
}
$configContent = @"
rendezvous_server = '$ServerIP'
nat_type = 1
serial = 0
[options]
custom-rendezvous-server = '$ServerIP'
key = '$Key'
"@
try {
$configContent | Set-Content -Path $configPath -Encoding UTF8
Write-Host "✅ Configuration written to: $configPath" -ForegroundColor Green
} catch {
Write-Error "❌ Failed to write configuration file: $($_.Exception.Message)"
exit 1
}
# ----------------- WRITE / APPEND LOG -----------------
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "[$timestamp] Tag: $latestTag | File: $($asset.name)"
try {
Add-Content -Path $logPath -Value $logEntry
Write-Host "📜 Log updated: $logPath" -ForegroundColor Yellow
} catch {
Write-Host "⚠️ Could not update log file: $($_.Exception.Message)" -ForegroundColor DarkYellow
}
# ----------------- START RUSTDESK -----------------
Write-Host "🚀 Starting RustDesk..." -ForegroundColor Cyan
try {
Start-Process -FilePath $exePath -WorkingDirectory $baseFolder
Write-Host "`n✅ RustDesk '$latestTag' (x64) downloaded, configured and started using ID server '$ServerIP'." -ForegroundColor Green
} catch {
Write-Error "❌ Failed to start RustDesk: $($_.Exception.Message)"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment