Skip to content

Instantly share code, notes, and snippets.

@noelhibbard
Last active February 21, 2024 15:04
Show Gist options
  • Save noelhibbard/1cbbf22734f9736663545f4171e897df to your computer and use it in GitHub Desktop.
Save noelhibbard/1cbbf22734f9736663545f4171e897df to your computer and use it in GitHub Desktop.
RustDesk Install Script
# You can download/execute the script by running this from an elevetad PowerShell:
# irm https://gist.githubusercontent.com/noelhibbard/1cbbf22734f9736663545f4171e897df/raw/f52b4569df4c72dc04760a75842134d5e5fa1727/Install-RustDesk.ps1 | iex
$ErrorActionPreference = 'silentlycontinue'
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
$rustdesk_cfg = Read-Host -Prompt "Config string" -AsSecureString
$rustdesk_pw = Read-Host -Prompt "Password (leave blank to generate a password)" -AsSecureString
$rustdesk_pw = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($rustdesk_pw))
$rustdesk_cfg = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($rustdesk_cfg))
if($rustdesk_pw -eq "") {
$autopassword = $True
$rustdesk_pw = (-join ((65..90) + (97..122) | Get-Random -Count 12 | % {[char]$_}))
}
$nightlyDownloadUrl = (((Invoke-RestMethod -UseBasicParsing -Uri https://api.github.com/repos/rustdesk/rustdesk/releases) | ? tag_name -eq "nightly").assets | ? name -like 'rustdesk-*-x86_64.exe').browser_download_url
$productionDownloadUrl = (((Invoke-RestMethod -UseBasicParsing -Uri https://api.github.com/repos/rustdesk/rustdesk/releases) | ? teg_name -ne "nightly")[0].assets | ? name -like 'rustdesk-*-x86_64.exe').browser_download_url
if (!(Test-Path C:\Temp)) {
New-Item -ItemType Directory -Force -Path C:\Temp > null
}
Set-Location C:\Temp
Invoke-WebRequest $nightlyDownloadUrl -Outfile "rustdesk.exe"
"Installing Rustdesk"
.\rustdesk.exe --silent-install
$ServiceName = 'Rustdesk'
while ((Get-Service -Name $ServiceName -ErrorAction SilentlyContinue).Status -ne 'Running') {
"Waiting for service"
Start-Service $ServiceName
Start-Sleep -seconds 5
}
Set-Location $env:ProgramFiles\RustDesk\
.\rustdesk.exe --get-id | Write-Output -OutVariable rustdesk_id | Out-Null
.\rustdesk.exe --config $rustdesk_cfg
.\rustdesk.exe --password $rustdesk_pw
Write-Output "RustDesk ID: $rustdesk_id"
if($autopassword) {
Write-Output "Password: $rustdesk_pw"
}
pause
@michele-tn
Copy link

michele-tn commented Feb 21, 2024

Hi,

i made a script for portable versions of Rustdesk.
In the hope of having done something pleasant.

script that I made, along the lines of the scripts below, downloads the latest version of Rustdesk (Nightly or Latest) using the GitHub API web service, configures the application by setting the IP and keys of your self-hosted server. Finally, it runs the application you just downloaded. That's all. ;-)

p.s.
PowerShell programming is absolutely not my comfort zone.. 👍
rustdesk/doc.rustdesk.com#309

PS Script Originally..:
rustdesk/rustdesk#7132

BR,

MT

<#                         
 .AUTHOR                                : MICHELE-TN
                            
 .CLIENT DEPLOYMENT          : https://rustdesk.com/docs/en/self-host/client-configuration/
                                               : https://rustdesk.com/docs/en/self-host/client-deployment/
                            
 .SERVER DEPLOYMENT          : https://rustdesk.com/docs/en/self-host/
 
 .Techahold/rustdeskinstall    : Easy install Script for Rustdesk
                                              : https://github.com/techahold/rustdeskinstall
#>


Function GetRustdesk([bool]$PreRelease, [string]$FileName){
    $repo = "rustdesk/rustdesk"
    $filenamePattern = "*x86_64.exe"
    $UriPattern = "*/nightly/*"

    if ($PreRelease) {
        $releasesUri = "https://api.github.com/repos/$repo/releases"   # Nightly version!!!
        
        [Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
        $downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object { $_.name -like $filenamePattern  -and  $_.browser_download_url -like $UriPattern}).browser_download_url
    } else {
        $releasesUri = "https://api.github.com/repos/$repo/releases/latest" # Latest version!!!
       
        [Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
        $downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url
    }
    
    Invoke-WebRequest -Uri $downloadUri -Out $FileName
}

Function ConfigSelfHostedServer([string]$pUsername){
    $IP_SelfHosted_Server = "'YOUR_SELF_HOSTED_SERVER_IP'"
    $KEY_SelfHosted_Server = "'YOUR_SELF_HOSTED_SERVER_KEY'"
    $nl = [Environment]::NewLine
    $n2 = $nl + $nl
    

    $CustomConfig  = 'rendezvous_server = ' + $IP_SelfHosted_Server         + $nl +
                     'nat_type = 1'                                         + $nl +
                     'serial = 0'                                           + $n2 +
                     '[options]'                                            + $nl +
                     'custom-rendezvous-server = ' + $IP_SelfHosted_Server  + $nl +
                     'key = ' + $KEY_SelfHosted_Server                      + $nl +
                     'relay-server = '''' '                                 + $nl +
                     'api-server = '''' ' 

    Set-Content C:\Users\$pUsername\AppData\Roaming\RustDesk\config\RustDesk2.toml $CustomConfig
}


function GetNconfigRustdesk([bool]$PreRelease){    

    [Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"

    if ($PreRelease){
        GetRustdesk 1 'rustdesk_nightly.exe'
        #Invoke-WebRequest "https://github.com/rustdesk/rustdesk/releases/download/nightly/rustdesk-1.2.4-x86_64.exe" -Outfile "rustdesk.exe"
        Start-Process .\rustdesk_nightly.exe
    } else{
        GetRustdesk 0 'rustdesk_latest.exe'
        Start-Process .\rustdesk_latest.exe
    }

    $username = ((Get-WMIObject -ClassName Win32_ComputerSystem).Username).Split('\')[1]
    $FilePath = "C:\Users\$username\AppData\Roaming\RustDesk\config\RustDesk2.toml"
    
    while (!(Test-Path -path $FilePath -PathType Leaf)){
        Write-Host "RustDesk2.toml does not exist" -f Yellow
    }
    
    if (Test-Path -path $FilePath -PathType Leaf) {
        Write-Host "RustDesk2.toml FOUND!!" -f Yellow

        if ($PreRelease){
            taskkill /im rustdesk_nightly.exe /f
        } else{
            taskkill /im rustdesk_latest.exe /f
        }
        
        Remove-Item C:\Users\$username\AppData\Roaming\RustDesk\config\RustDesk2.toml
        New-Item    C:\Users\$username\AppData\Roaming\RustDesk\config\RustDesk2.toml

        ConfigSelfHostedServer($username)


        if ($PreRelease){
            Start-Process .\rustdesk_nightly.exe
        } else{
            Start-Process .\rustdesk_latest.exe
        }
    }
}



cls
# Run as administrator and stays in the current directory
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) {
        Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
    }
}

GetNconfigRustdesk 1 #NIGHTLY
#GetNconfigRustdesk 0 #LATEST RELEASE!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment