Created
July 2, 2026 17:15
-
-
Save hintoz/a0eb65502b6405c67163ca64fdd4ebd8 to your computer and use it in GitHub Desktop.
A modified script for downloading and installing the latest version of RustDesk for Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference= 'silentlycontinue' | |
| # Assign the value random password to the password variable | |
| $rustdesk_pw=(-join ((65..90) + (97..122) | Get-Random -Count 12 | % {[char]$_})) | |
| # Provide a link to your script. | |
| # If you use the script to host it on your server and run it through 'curl -sL https://domain.ru/script.sh | bash' | |
| $script_url="" | |
| # Get your config string from your Web portal and Fill Below | |
| $rustdesk_cfg="configstring" | |
| ################################## Please Do Not Edit Below This Line ######################################### | |
| # Automatically determine the URL from which the script was launched. | |
| if ($MyInvocation.Line -match 'irm\s+([^\s|]+)') { | |
| $Url = $Matches[1] | |
| # If the user forgot to specify https://, we add it for the stability of the Start-Process. | |
| if ($Url -notlike "http*") { $Url = "https://$Url" } | |
| } else { | |
| # Backup option in case the script was run locally as a file | |
| $Url = $script_url | |
| } | |
| # Check the administrator rights | |
| if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | |
| { | |
| if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) | |
| { | |
| # Restart PowerShell from the admin and download the script again using the automatically found URL. | |
| Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -NoExit -Command `"irm $Url | iex`""; | |
| Exit; | |
| } | |
| } | |
| # This function will return the latest version and download link as an object | |
| function getLatest() | |
| { | |
| $Page = Invoke-WebRequest -Uri 'https://github.com/rustdesk/rustdesk/releases/latest' -UseBasicParsing | |
| $HTML = New-Object -Com "HTMLFile" | |
| try | |
| { | |
| $HTML.IHTMLDocument2_write($Page.Content) | |
| } | |
| catch | |
| { | |
| $src = [System.Text.Encoding]::Unicode.GetBytes($Page.Content) | |
| $HTML.write($src) | |
| } | |
| # Current example link: https://github.com/rustdesk/rustdesk/releases/download/1.2.6/rustdesk-1.2.6-x86_64.exe | |
| $Downloadlink = ($HTML.Links | Where {$_.href -match '(.)+\/rustdesk\/rustdesk\/releases\/download\/\d{1}.\d{1,2}.\d{1,2}(.{0,3})\/rustdesk(.)+x86_64.exe'} | select -first 1).href | |
| # bugfix - sometimes you need to replace "about:" | |
| $Downloadlink = $Downloadlink.Replace('about:', 'https://github.com') | |
| $Version = "unknown" | |
| if ($Downloadlink -match './rustdesk/rustdesk/releases/download/(?<content>.*)/rustdesk-(.)+x86_64.exe') | |
| { | |
| $Version = $matches['content'] | |
| } | |
| if ($Version -eq "unknown" -or $Downloadlink -eq "") | |
| { | |
| Write-Output "ERROR: Version or download link not found." | |
| Read-Host "Press Enter to exit" | |
| Exit; | |
| } | |
| # Create object to return | |
| $params += @{Version = $Version} | |
| $params += @{Downloadlink = $Downloadlink} | |
| $Result = New-Object PSObject -Property $params | |
| return($Result) | |
| } | |
| $RustDeskOnGitHub = getLatest | |
| $rdver = ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk\").Version) | |
| $installed = ($rdver -ne $null); | |
| if ($rdver -eq $RustDeskOnGitHub.Version) | |
| { | |
| Write-Output "RustDesk $rdver is the newest version." | |
| Read-Host "Press Enter to exit" | |
| Exit; | |
| } | |
| if (!(Test-Path C:\Temp)) | |
| { | |
| New-Item -ItemType Directory -Force -Path C:\Temp | Out-Null | |
| } | |
| cd C:\Temp | |
| Invoke-WebRequest $RustDeskOnGitHub.Downloadlink -Outfile "rustdesk.exe" | |
| Start-Process .\rustdesk.exe --silent-install | |
| Start-Sleep -seconds 20 | |
| $ServiceName = 'Rustdesk' | |
| $arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue | |
| if ($arrService -eq $null) | |
| { | |
| Write-Output "Installing service" | |
| cd $env:ProgramFiles\RustDesk | |
| Start-Process .\rustdesk.exe --install-service | |
| Start-Sleep -seconds 20 | |
| $arrService = Get-Service -Name $ServiceName | |
| } | |
| while ($arrService.Status -ne 'Running') | |
| { | |
| Start-Service $ServiceName | |
| Start-Sleep -seconds 5 | |
| $arrService.Refresh() | |
| } | |
| cd $env:ProgramFiles\RustDesk\ | |
| .\rustdesk.exe --get-id | Write-Output -OutVariable rustdesk_id | |
| .\rustdesk.exe --config $rustdesk_cfg | |
| if (-Not $installed) | |
| { | |
| .\rustdesk.exe --password $rustdesk_pw | |
| } | |
| Write-Output "..............................................." | |
| # Show the value of the ID Variable | |
| Write-Output "RustDesk ID: $rustdesk_id" | |
| # Show the value of the Password Variable | |
| Write-Output "Password: $rustdesk_pw" | |
| Write-Output "..............................................." | |
| Read-Host "Press Enter to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment