rustdesk / doc.rustdesk.com

Document of RustDesk
https://rustdesk.com/docs/
MIT License
379 stars 368 forks source link

PowerShell Script - Client Installation #309

Open stephannn opened 1 year ago

stephannn commented 1 year ago

Hi, I had two issues with the script:

  1. the variable rustdesk_cfg was not defined correctly
  2. the install argument did not install the service
  3. the variable $rustdesk_id was not filled

`$ErrorActionPreference= 'silentlycontinue'

Assign the value random password to the password variable

$rustdeskpw=(-join ((65..90) + (97..122) | Get-Random -Count 12 | % {[char]$}))

Get your config string from your Web portal and Fill Below

$rustdesk_cfg = "=0nI9EUOpd0UzEHWY5UbSFWaSBXWnl2R1FWTQFFOSF3YyFkU3pmd5g3KLF3QQRlI6ISeltmIsIiI6ISawFmIsIiI6ISehxWZyJCLiQ3clRnLl5Wd05Waus2clRGdzVnciojI0N3boJye"

################################### Please Do Not Edit Below This Line #########################################

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';""; Exit; } }

$rdver = ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk\").Version)

if($rdver -eq "1.2.2") { Write-Output "RustDesk $rdver is the newest version" Exit }

If (!(Test-Path C:\Temp)) { New-Item -ItemType Directory -Force -Path C:\Temp > null }

cd C:\Temp

Write-Host "Download rustdesk" Invoke-WebRequest "https://github.com/rustdesk/rustdesk/releases/download/1.2.2/rustdesk-1.2.2-x86_64.exe" -Outfile "rustdesk.exe" Write-Host "Install rustdesk" Start-Process .\rustdesk.exe --silent-install -wait -Verbose

$ServiceName = 'Rustdesk' $arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue

if ($arrService -eq $null) { Write-Host "Wait 20 seconds" Start-Sleep -seconds 20 }

$arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue

if ($arrService -eq $null) { Write-Host "Install service" cd $env:ProgramFiles\RustDesk\ Start-Process .\rustdesk.exe --install-service -wait -Verbose Start-Sleep -seconds 20 }

$arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue

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

.\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 "..............................................."`

Sorry for the formation

rustdesk commented 1 year ago

@dinger1986

dinger1986 commented 1 year ago

Hello,

  1. the config shouldnt have the = before it https://rustdesk.com/docs/en/self-host/client-configuration/#automatic-config
  2. there is no "argument" to install the service thats down to the exe installer, also if it proceeded to the end of the script it has to have installed the service as theres a check in the script.
  3. Works fine for me, are you running as admin? Or using an RMM or Intune to install?
dinger1986 commented 1 year ago

also your string isnt setting the API, just the host and key

stephannn commented 1 year ago

Hi, I am referring to https://rustdesk.com/docs/en/self-host/client-deployment/

dinger1986 commented 1 year ago

sorry I get you now, thanks, have made the changes

noelhibbard commented 7 months ago

Here is the script I use: https://gist.github.com/noelhibbard/1cbbf22734f9736663545f4171e897df

It prompts for the config string you want to use and a password. If you don't supply a password it will generate one for you and at the end of the script it will display the ID and the generated password (if one was generated). It also queries the GitHub repo for the latest nightly build.

michele-tn commented 7 months ago

sorry I get you now, thanks, have made the changes

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

PS Script Originally..: https://github.com/rustdesk/rustdesk/discussions/7132

BR,

MT

GetRUSTDESKLatestVersion_NIGHTLY.ps1

rustdesk commented 7 months ago

@michele-tn what does this do?

michele-tn commented 7 months ago

@michele-tn what does this do?

Hi,

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. ;-)

GetRUSTDESKLatestVersion_NIGHTLY.ps1

p.s. PowerShell programming is absolutely not my comfort zone.. 👍

https://gist.github.com/MarkTiedemann/c0adc1701f3f5c215fc2c2d5b1d5efd3 https://gist.github.com/Splaxi/fe168eaa91eb8fb8d62eba21736dc88a