2022-08-03 00:59:40 +02:00
$ErrorActionPreference = 'silentlycontinue'
2022-08-29 16:01:55 +02:00
#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 ;
}
}
2022-08-12 10:09:08 +02:00
# Replace wanipreg and keyreg with the relevant info for your install. IE wanipreg becomes your rustdesk server IP or DNS and keyreg becomes your public key.
2022-08-03 00:59:40 +02:00
2022-08-22 10:21:34 +02:00
$rustdesk_url = 'https://github.com/rustdesk/rustdesk/releases/latest'
$request = [ System.Net.WebRequest ] :: Create ( $rustdesk_url )
2022-08-17 16:42:02 +02:00
$response = $request . GetResponse ( )
$realTagUrl = $response . ResponseUri . OriginalString
2022-08-22 10:21:34 +02:00
$rustdesk_version = $realTagUrl . split ( '/' ) [ -1 ] . Trim ( 'v' )
2022-08-22 12:08:54 +02:00
Write-Output ( " Installing Rustdesk version $rustdesk_version " )
2022-08-17 16:42:02 +02:00
function OutputIDandPW([String]$rustdesk_id , [ String ] $rustdesk_pw ) {
Write-Output ( " ###################################################### " )
Write-Output ( " # # " )
Write-Output ( " # CONNECTION PARAMETERS: # " )
Write-Output ( " # # " )
Write-Output ( " ###################################################### " )
Write-Output ( " " )
Write-Output ( " RustDesk-ID: $rustdesk_id " )
Write-Output ( " RustDesk-Password: $rustdesk_pw " )
2022-08-17 16:44:43 +02:00
Write-Output ( " " )
2022-08-03 00:59:40 +02:00
}
2022-08-17 16:42:02 +02:00
If ( ! ( Test-Path $env:Temp ) ) {
New-Item -ItemType Directory -Force -Path $env:Temp > null
}
2022-08-17 17:08:33 +02:00
If ( ! ( Test-Path " $env:ProgramFiles \Rustdesk\RustDesk.exe " ) ) {
2022-08-17 16:42:02 +02:00
cd $env:Temp
2022-08-17 17:01:08 +02:00
If ( [ Environment ] :: Is64BitOperatingSystem ) {
$os_arch = " x64 "
} Else {
$os_arch = " x32 "
}
2022-08-22 12:08:54 +02:00
Invoke-WebRequest https : / / github . com / rustdesk / rustdesk / releases / download / $rustdesk_version / rustdesk - $rustdesk_version -windows_ $os_arch . zip -Outfile rustdesk . zip
2022-08-17 16:42:02 +02:00
Expand-Archive rustdesk . zip
cd rustdesk
2022-08-28 23:20:20 +02:00
Start-Process " rustdesk- $rustdesk_version -putes.exe " -argumentlist " --silent-install " -wait
2022-08-17 16:42:02 +02:00
# Set URL Handler
New-Item -Path " HKLM:\SOFTWARE\Classes\RustDesk " > null
Set-ItemProperty -Path " HKLM:\SOFTWARE\Classes\RustDesk " -Name " (Default) " -Value " URL:RustDesk Protocol " > null
New-ItemProperty -Path " HKLM:\SOFTWARE\Classes\RustDesk " -Name " URL Protocol " -Type STRING > null
New-Item -Path " HKLM:\SOFTWARE\Classes\RustDesk\DefaultIcon " > null
Set-ItemProperty -Path " HKLM:\SOFTWARE\Classes\RustDesk\DefaultIcon " -Name " (Default) " -Value " RustDesk.exe,0 " > null
New-Item -Path " HKLM:\SOFTWARE\Classes\RustDesk\shell " > null
New-Item -Path " HKLM:\SOFTWARE\Classes\RustDesk\shell\open " > null
New-Item -Path " HKLM:\SOFTWARE\Classes\RustDesk\shell\open\command " > null
$rustdesklauncher = '"' + $env:ProgramFiles + '\RustDesk\RustDeskURLLauncher.exe" %1"'
Set-ItemProperty -Path " HKLM:\SOFTWARE\Classes\RustDesk\shell\open\command " -Name " (Default) " -Value $rustdesklauncher > null
2022-08-17 17:56:31 +02:00
Install-PackageProvider -Name NuGet -MinimumVersion 2.8 . 5 . 201 -Force > null
Install-Module ps2exe -Force > null
2022-08-17 16:42:02 +02:00
$urlhandler_ps1 = @"
`$ url_handler = `$ args [ 0 ]
`$ rustdesk_id = `$ url_handler -creplace '(?s)^.*\:' , ''
2022-08-17 17:08:33 +02:00
Start-Process -FilePath '$env:ProgramFiles\RustDesk\rustdesk.exe' -ArgumentList " --connect `$ rustdesk_id "
2022-08-17 16:42:02 +02:00
" @
New-Item " $env:ProgramFiles \RustDesk\urlhandler.ps1 " > null
Set-Content " $env:ProgramFiles \RustDesk\urlhandler.ps1 " $urlhandler_ps1 > null
Invoke-Ps2Exe " $env:ProgramFiles \RustDesk\urlhandler.ps1 " " $env:ProgramFiles \RustDesk\RustDeskURLLauncher.exe " > null
2022-08-17 17:01:08 +02:00
# Cleanup Tempfiles
2022-08-17 17:56:31 +02:00
Remove-Item " $env:ProgramFiles \RustDesk\urlhandler.ps1 " > null
2022-08-17 17:01:08 +02:00
cd $env:Temp
2022-08-17 17:56:31 +02:00
Remove-Item $env:Temp \ rustdesk -Recurse > null
Remove-Item $env:Temp \ rustdesk . zip > null
2022-08-09 01:02:25 +02:00
}
2022-08-05 12:51:15 +02:00
2022-08-09 01:05:28 +02:00
# Write config
2022-08-17 16:42:02 +02:00
$RustDesk2_toml = @"
rendezvous_server = 'wanipreg'
nat_type = 1
serial = 0
[ options ]
custom-rendezvous -server = 'wanipreg'
2022-08-17 19:54:35 +02:00
key = 'keyreg'
2022-08-17 16:42:02 +02:00
relay-server = 'wanipreg'
api-server = 'https://wanipreg'
2022-08-17 18:13:00 +02:00
enable-audio = 'N'
2022-08-17 16:42:02 +02:00
" @
2022-08-17 17:56:31 +02:00
If ( ! ( Test-Path $env:AppData \ RustDesk \ config \ RustDesk2 . toml ) ) {
New-Item $env:AppData \ RustDesk \ config \ RustDesk2 . toml > null
}
Set-Content $env:AppData \ RustDesk \ config \ RustDesk2 . toml $RustDesk2_toml > null
If ( ! ( Test-Path $env:WinDir \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml ) ) {
New-Item $env:WinDir \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml > null
}
Set-Content $env:WinDir \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml $RustDesk2_toml > null
2022-08-03 00:59:40 +02:00
2022-08-28 23:20:20 +02:00
$random_pass = ( -join ( ( 65 . .90 ) + ( 97 . .122 ) | Get-Random -Count 8 | % { [ char ] $_ } ) )
Start-Process " $env:ProgramFiles \RustDesk\RustDesk.exe " -argumentlist " --password $random_pass " -wait
2022-08-09 16:16:19 +02:00
2022-08-03 00:59:40 +02:00
# Get RustDesk ID
2022-08-17 17:08:33 +02:00
If ( ! ( " $env:WinDir \ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk.toml " ) ) {
2022-08-17 16:42:02 +02:00
$rustdesk_id = ( Get-Content $env:AppData \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " id " ) } )
$rustdesk_id = $rustdesk_id . Split ( " ' " ) [ 1 ]
$rustdesk_pw = ( Get-Content $env:AppData \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " password " ) } )
$rustdesk_pw = $rustdesk_pw . Split ( " ' " ) [ 1 ]
Write-Output ( " Config file found in user folder " )
OutputIDandPW $rustdesk_id $rustdesk_pw
} Else {
2022-08-17 17:08:33 +02:00
$rustdesk_id = ( Get-Content $env:WinDir \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " id " ) } )
2022-08-17 16:42:02 +02:00
$rustdesk_id = $rustdesk_id . Split ( " ' " ) [ 1 ]
2022-08-17 17:08:33 +02:00
$rustdesk_pw = ( Get-Content $env:WinDir \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " password " ) } )
2022-08-17 16:42:02 +02:00
$rustdesk_pw = $rustdesk_pw . Split ( " ' " ) [ 1 ]
Write-Output " Config file found in windows service folder "
OutputIDandPW $rustdesk_id $rustdesk_pw
2022-08-09 16:16:19 +02:00
}
2022-08-03 00:59:40 +02:00
2022-08-17 17:56:31 +02:00
Stop-Process -Name RustDesk -Force > null
Start-Service -Name RustDesk > null