fix: reliable RustDesk config (stop processes, write to all paths, registry, CLI apply)
This commit is contained in:
parent
10476fcacd
commit
f7fd55344d
143
rd_setup.ps1
143
rd_setup.ps1
|
|
@ -52,18 +52,15 @@ try {
|
|||
|
||||
# Vibiraem nuzhnyj fayl po arhitekture
|
||||
if ($isX86) {
|
||||
# Dlya 32-bit: sciter versiya
|
||||
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk.*x86.*sciter" } | Select-Object -First 1).name
|
||||
if (-not $rdFile) {
|
||||
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk.*x86" } | Select-Object -First 1).name
|
||||
}
|
||||
} else {
|
||||
# Dlya 64-bit: x86_64 versiya
|
||||
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk.*x86_64" } | Select-Object -First 1).name
|
||||
}
|
||||
|
||||
if (-not $rdFile) {
|
||||
# Fallback: lyuboy rustdesk fayl
|
||||
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk" } | Select-Object -First 1).name
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +71,6 @@ try {
|
|||
|
||||
Write-Host " Selected: $rdFile" -ForegroundColor Green
|
||||
} catch {
|
||||
# Fallback: esli API nedostupen
|
||||
if ($isX86) {
|
||||
$rdFile = "rustdesk-1.4.6-x86-sciter.exe"
|
||||
} else {
|
||||
|
|
@ -104,14 +100,15 @@ if ($result.ExitCode -eq 0 -or $result.ExitCode -eq 3010) {
|
|||
# ============================================================
|
||||
Write-Host "[3/5] Configuring relay server..." -ForegroundColor Yellow
|
||||
|
||||
# RustDesk hranit nastrojki v registru i v config-fajle
|
||||
# 1) Reestr (HKEY_LOCAL_MACHINE) — dlya vseh polzovatelej
|
||||
$rdRegPath = "HKLM:\SOFTWARE\RustDesk"
|
||||
if (-not (Test-Path $rdRegPath)) {
|
||||
New-Item -Path $rdRegPath -Force | Out-Null
|
||||
}
|
||||
# Formiruem TOML config
|
||||
$tomlContent = @"
|
||||
[options]
|
||||
custom-rendezvous-server = "$RD_HOST"
|
||||
relay-server = "$RD_HOST"
|
||||
key = "$RD_KEY"
|
||||
"@
|
||||
|
||||
# Proverayem kuda ustanovlen RustDesk
|
||||
# Nahodim RustDesk.exe
|
||||
$rdExePaths = @(
|
||||
"C:\Program Files\RustDesk\RustDesk.exe",
|
||||
"${env:ProgramFiles(x86)}\RustDesk\RustDesk.exe",
|
||||
|
|
@ -120,65 +117,75 @@ $rdExePaths = @(
|
|||
$rdExe = $rdExePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
|
||||
|
||||
if (-not $rdExe) {
|
||||
Write-Host " RustDesk.exe not found, trying registry config..." -ForegroundColor Yellow
|
||||
}
|
||||
Write-Host " RustDesk.exe NOT found" -ForegroundColor Red
|
||||
Write-Host " Skipping config..." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host " Found: $rdExe" -ForegroundColor Green
|
||||
|
||||
# 2) Config fayl — RustDesk ispolzuet JSON/TOML config
|
||||
# Path: C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk2.toml
|
||||
# Ili dlya tekushchego polzovatelya: %APPDATA%\RustDesk\config\RustDesk2.toml
|
||||
|
||||
$rdConfigDir = "$env:APPDATA\RustDesk\config"
|
||||
$rdConfigFile = "$rdConfigDir\RustDesk2.toml"
|
||||
|
||||
# Sozdayem papku esli net
|
||||
New-Item -ItemType Directory -Path $rdConfigDir -Force | Out-Null
|
||||
|
||||
# Proveryaem sushestvuet li config
|
||||
$createNew = $true
|
||||
if (Test-Path $rdConfigFile) {
|
||||
$createNew = $false
|
||||
Write-Host " Existing config found, updating..." -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# Formiruem soderzhimoe TOML
|
||||
$tomlContent = @"
|
||||
[options]
|
||||
custom-rendezvous-server = "$RD_HOST"
|
||||
relay-server = "$RD_HOST"
|
||||
key = "$RD_KEY"
|
||||
"@
|
||||
|
||||
$tomlContent | Set-Content $rdConfigFile -Encoding UTF8 -Force
|
||||
Write-Host " User config written" -ForegroundColor Green
|
||||
|
||||
# Takzhe zapisyvaem v reestr dlya system-level
|
||||
if ($rdExe) {
|
||||
$rdDir = Split-Path $rdExe
|
||||
$systemConfigDir = "$rdDir\config"
|
||||
$systemConfigFile = "$systemConfigDir\RustDesk2.toml"
|
||||
|
||||
New-Item -ItemType Directory -Path $systemConfigDir -Force | Out-Null
|
||||
$tomlContent | Set-Content $systemConfigFile -Encoding UTF8 -Force
|
||||
Write-Host " System config written" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Registry keys (dlya avtozapuska servisa)
|
||||
$serviceRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\rustdesk"
|
||||
$rustdeskService = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue
|
||||
|
||||
if ($rustdeskService) {
|
||||
# Ostanavlivаем servis pered nastrojkoj
|
||||
Write-Host " Stopping RustDesk service..." -ForegroundColor Gray
|
||||
# Ostanavlivаем vse processy i servisy RustDesk chtoby ne perenezli config
|
||||
Write-Host " Stopping RustDesk processes..." -ForegroundColor Gray
|
||||
Get-Process -Name "RustDesk" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Stop-Service -Name "RustDesk" -Force -ErrorAction SilentlyContinue
|
||||
Stop-Service -Name "RustDesk Tray" -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
# === 1) Config dlya tekushchego polzovatelya ===
|
||||
$userConfigDir = "$env:APPDATA\RustDesk\config"
|
||||
$userConfigFile = "$userConfigDir\RustDesk2.toml"
|
||||
New-Item -ItemType Directory -Path $userConfigDir -Force | Out-Null
|
||||
$tomlContent | Set-Content $userConfigFile -Encoding UTF8 -Force
|
||||
Write-Host " User config: OK" -ForegroundColor Green
|
||||
|
||||
# === 2) Config dlya servisa (LocalService) ===
|
||||
$svcConfigDir = "C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config"
|
||||
$svcConfigFile = "$svcConfigDir\RustDesk2.toml"
|
||||
New-Item -ItemType Directory -Path $svcConfigDir -Force | Out-Null
|
||||
$tomlContent | Set-Content $svcConfigFile -Encoding UTF8 -Force
|
||||
Write-Host " Service config: OK" -ForegroundColor Green
|
||||
|
||||
# === 3) Config ryadom s exe (system-level) ===
|
||||
$rdDir = Split-Path $rdExe
|
||||
$exeConfigDir = "$rdDir\config"
|
||||
$exeConfigFile = "$exeConfigDir\RustDesk2.toml"
|
||||
New-Item -ItemType Directory -Path $exeConfigDir -Force | Out-Null
|
||||
$tomlContent | Set-Content $exeConfigFile -Encoding UTF8 -Force
|
||||
Write-Host " EXE config: OK" -ForegroundColor Green
|
||||
|
||||
# === 4) Reestr HKLM ===
|
||||
$rdRegPath = "HKLM:\SOFTWARE\RustDesk"
|
||||
if (-not (Test-Path $rdRegPath)) {
|
||||
New-Item -Path $rdRegPath -Force | Out-Null
|
||||
}
|
||||
Set-ItemProperty -Path $rdRegPath -Name "CustomRelayServer" -Value "$RD_HOST" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path $rdRegPath -Name "RelayServer" -Value "$RD_HOST" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path $rdRegPath -Name "Key" -Value "$RD_KEY" -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Registry: OK" -ForegroundColor Green
|
||||
|
||||
# === 5) Reestr HKCU ===
|
||||
$rdRegPathCU = "HKCU:\SOFTWARE\RustDesk"
|
||||
if (-not (Test-Path $rdRegPathCU)) {
|
||||
New-Item -Path $rdRegPathCU -Force | Out-Null
|
||||
}
|
||||
Set-ItemProperty -Path $rdRegPathCU -Name "CustomRelayServer" -Value "$RD_HOST" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path $rdRegPathCU -Name "RelayServer" -Value "$RD_HOST" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path $rdRegPathCU -Name "Key" -Value "$RD_KEY" -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Registry (user): OK" -ForegroundColor Green
|
||||
|
||||
# === 6) Zapusk s parametrami dlya primeneniya ===
|
||||
Write-Host " Applying config via CLI..." -ForegroundColor Gray
|
||||
Start-Process $rdExe -ArgumentList "--config-server=$RD_HOST","--key=$RD_KEY" -Wait -PassThru -NoNewWindow -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
# Ostanavlivaem chtoby servis mog zapustitsya chisto
|
||||
Get-Process -Name "RustDesk" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
# Zapuskem s nastrojkami
|
||||
Write-Host " Starting RustDesk service..." -ForegroundColor Gray
|
||||
Start-Service -Name "RustDesk" -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host " RustDesk service restarted" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host " RustDesk service not found (running as app)" -ForegroundColor Yellow
|
||||
# Zapuskem servis
|
||||
$rustdeskService = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue
|
||||
if ($rustdeskService) {
|
||||
Start-Service -Name "RustDesk" -ErrorAction SilentlyContinue
|
||||
Write-Host " Service: started" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
|
|
@ -213,8 +220,8 @@ Write-Host "`nRelay Server: $RD_HOST" -ForegroundColor Cyan
|
|||
Write-Host "Key: $RD_KEY" -ForegroundColor Cyan
|
||||
|
||||
if ($rdExe) {
|
||||
Write-Host "`nRustDesk path: $rdExe" -ForegroundColor Yellow
|
||||
Write-Host "`nRustDesk: $rdExe" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host "`nZapustite RustDesk i podklyuchaytes cherez vash server." -ForegroundColor Green
|
||||
Write-Host "`nRustDesk gotov k rabote cherez vash server." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue