# This script updates the user's RustDesk2.toml (configuration) file to use # VerrilloTrading relay server. It asks for elevated privileges only to stop # the RustDesk Service, the rest of the script runs as the user. This script # does not change any system files, only stops RustDesk service and makes # changes to RustDesk config files. # # This script also stops the RustDesk Service from running on your system on # startup. This means that in order for us or anybody to request a remote # desktop connection, you must be running the RustDesk application, it is never # running in the background like it does with the RustDesk Service. This is # more secure. # # You can run this script again if you made changes to the RustDesk network # settings by accident or if you were using another relay server temporarily. # This script will autopopulate the required settings for VerrilloTrading relay # server. If you go ahead and manually change the network settings in RustDesk # you will need to run this script again to connect to our relay server. # # There is no danger in executing this script. # param ( [switch]$ElevatedServiceStop # Flag to indicate elevated execution ) # Function to stop the RustDesk service (runs elevated) function Stop-RustDeskService { $rustDeskService = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue if ($rustDeskService) { Write-Host "Found RustDesk service. Current status: $($rustDeskService.Status)" if ($rustDeskService.Status -eq "Running") { Write-Host "Stopping RustDesk service to prevent config overwrite..." Stop-Service -Name "RustDesk" -Force -ErrorAction Stop # Disable the service from starting on boot Write-Host "Disabling RustDesk service from running on system startup..." Set-Service -Name "RustDesk" -StartupType Disabled Start-Sleep -Seconds 2 } else { Write-Host "RustDesk service is not running (Status: $($rustDeskService.Status))." } } else { Write-Host "RustDesk service not found." } } # Check if this is the elevated service-stop execution if ($ElevatedServiceStop) { Stop-RustDeskService exit # Exit after stopping the service } # Check if admin privileges are needed to stop the service if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { $rustDeskService = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue if ($rustDeskService -and $rustDeskService.Status -eq "Running") { Write-Host "RustDesk Service is running and requires administrative privileges to stop. Requesting elevation..." Start-Sleep -Seconds 2 # Relaunch this script with the -ElevatedServiceStop flag in an elevated session $scriptUrl = "https://verrillotrading.com/rustdesk-windows-setup" Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command & { Invoke-RestMethod '$scriptUrl' | Invoke-Expression } -ElevatedServiceStop" -Verb RunAs # Wait for the service to stop or timeout (e.g., 10 seconds) $timeoutSeconds = 4 $waitIntervalSeconds = 1 $elapsedSeconds = 0 Write-Host "Waiting for RustDesk service to stop..." # debug # Start-Sleep -Seconds 5 while ($elapsedSeconds -lt $timeoutSeconds) { $rustDeskServicePostElevation = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue if (-not $rustDeskServicePostElevation -or $rustDeskServicePostElevation.Status -ne "Running") { Write-Host "Success: Service is stopped. Proceeding..." break } Start-Sleep -Seconds $waitIntervalSeconds $elapsedSeconds += $waitIntervalSeconds } # Check if the service is still running after waiting $rustDeskServicePostElevation = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue if ($rustDeskServicePostElevation -and $rustDeskServicePostElevation.Status -eq "Running") { Write-Host "Failed: RustDesk Service is still running. It must be stopped for this script to work properly.`nPlease run this script again and approve the UAC prompt to allow stopping the service, or stop the RustDesk Service manually via Services (services.msc) and run again." # Pause return } } } # Rest of the script runs as user (no elevation required beyond service stop) # Write-Host "Proceeding with configuration..." # Check if RustDesk.exe is running and terminate it $rustDeskProcess = Get-Process -Name "RustDesk" -ErrorAction SilentlyContinue if ($rustDeskProcess) { # Write-Host "RustDesk is running. Closing it now..." Stop-Process -Name "RustDesk" -Force -ErrorAction SilentlyContinue # Wait a moment to ensure it’s fully closed # Start-Sleep -Seconds 2 } # Redundant Disable RustDesk Service (for some reason this was required) Write-Host "Disabling RustDesk service from running on system startup..." Set-Service -Name "RustDesk" -StartupType Disabled -ErrorAction SilentlyContinue # Define the path to RustDesk2.toml $configPath = "$env:APPDATA\RustDesk\config\RustDesk2.toml" $rustDeskExePath = "C:\Program Files\RustDesk\RustDesk.exe" # Check if RustDesk2.toml exists; if not, try to start RustDesk if (-not (Test-Path $configPath)) { Write-Host "RustDesk2.toml not found. Attempting to start RustDesk to generate it..." if (Test-Path $rustDeskExePath) { Start-Process -FilePath $rustDeskExePath # Wait a bit for RustDesk to create the config file Start-Sleep -Seconds 2 # Check again if the file exists if (-not (Test-Path $configPath)) { Write-Host "Operation failed: Please install and run RustDesk manually one time before running this script." Pause Return } else { Write-Host "Success: Closing RustDesk and Proceeding..." # Close RustDesk now that the config files were autogenerated Stop-Process -Name "RustDesk" -Force -ErrorAction SilentlyContinue # Wait a moment to ensure it’s fully closed Start-Sleep -Seconds 2 } } else { Write-Host "Could not find RustDesk.exe at $rustDeskExePath." Write-Host "Operation failed: Please install and run RustDesk manually one time before running this script." Pause Return } } # Define the desired configuration lines $desiredLines = @{ "custom-rendezvous-server" = "custom-rendezvous-server = '178.156.134.213'" "relay-server" = "relay-server = '178.156.134.213'" "key" = "key = '00Faq92+WCmEvsPfDmJiC8kXVBvYbMAP2LCEE+eRIgU='" } # read RustDesk2.toml (it already exists because we started rustdesk) if (Test-Path $configPath) { $existingLines = Get-Content -Path $configPath | Where-Object { $_ -ne "" } # Read line-by-line $updatedLines = @() $foundKeys = @{} # Process each line, replacing matching keys foreach ($line in $existingLines) { $trimmedLine = $line.Trim() $replaced = $false foreach ($key in $desiredLines.Keys) { if ($trimmedLine -like "$key*") { $updatedLines += $desiredLines[$key] $foundKeys[$key] = $true $replaced = $true break } } if (-not $replaced) { $updatedLines += $line # Keep non-matching lines } } # Add any missing keys $needsUpdate = $false foreach ($key in $desiredLines.Keys) { if (-not $foundKeys.ContainsKey($key)) { $updatedLines += $desiredLines[$key] $needsUpdate = $true } } # Write the updated content back to the file $newContent = ($updatedLines -join "`n") + "`n" Set-Content -Path $configPath -Value $newContent -Force -ErrorAction Stop if ($foundKeys.Count -gt 0 -or $needsUpdate) { Write-Host "Success: Configuration file was updated to use VerrilloTrading Relay server." } else { Write-Host "Success: Configuration file already matches VerrilloTrading Relay server settings." } } # Try to restart RustDesk.exe if (Test-Path $rustDeskExePath) { Write-Host "Success: Starting RustDesk." Start-Process -FilePath $rustDeskExePath } else { Write-Host "Could not find RustDesk.exe in the default location. Please start RustDesk manually." } # Notify the user Write-Host "Success: RustDesk is now setup to receive support by VerrilloTrading." Write-Host "If you have any questions, contact support@verrillotrading.com"