This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
forked from techahold/rustdeskinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsAgentAIOInstall.ps1
167 lines (138 loc) · 6.47 KB
/
WindowsAgentAIOInstall.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<#
.SYNOPSIS
Install and configure RustDesk Client
.DESCRIPTION
Deployment script to deploy the latest RustDesk (https://rustdesk.com/) client on a windows computer. Use described parameters to configure the client.
.PARAMETER WanIPReg
The IP address or FQDN of the RustDesk ID Server and Relay Server
.PARAMETER KeyReg
Specifies the key of ID/Relay Server
.PARAMETER PasswordLength
Specifies the length of the password to connect to the RustDesk client
.PARAMETER EnableAudio
EnableAudio in RustDesk client.
.EXAMPLE
.\WindowsAgentAIOInstall.ps1 -WanIPREG "somehost.example.tld" -KeyReg "KeyFromServer="
Install RustDesk Client by defining a different ID/Relay server and corresponding key
.EXAMPLE
.\WindowsAgentAIOInstall.ps1 -WanIPREG "somehost.example.tld" -KeyReg "KeyFromServer=" -PasswordLength 24
Optionally define length for client password
.EXAMPLE
.\WindowsAgentAIOInstall.ps1 -WanIPREG "somehost.example.tld" -KeyReg "KeyFromServer=" -EnableAudio 0
Optionally disable audio
#>
Param(
[string]$WanIPReg = "wanipreg",
[string]$KeyReg = "keyreg",
[int]$PasswordLength = 8,
[bool]$EnableAudio = $True
)
$ErrorActionPreference= 'silentlycontinue'
#Requires -RunAsAdministrator
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")
Write-Output("")
}
If (!(Test-Path $env:Temp)) {
New-Item -ItemType Directory -Force -Path $env:Temp > null
}
If (!(Test-Path "$env:ProgramFiles\Rustdesk\RustDesk.exe")) {
cd $env:Temp
If ([Environment]::Is64BitOperatingSystem) {
$os_arch = "x64"
} Else {
$os_arch = "x32"
}
#Get latest version number
$restdesk_url = 'https://github.com/rustdesk/rustdesk/releases/latest'
$request = [System.Net.WebRequest]::Create($restdesk_url)
$response = $request.GetResponse()
$realTagUrl = $response.ResponseUri.OriginalString
$restdesk_version = $realTagUrl.split('/')[-1].Trim('v')
Write-Output("Installing RestDesk version $restdesk_version")
Invoke-WebRequest https://github.com/rustdesk/rustdesk/releases/download/$restdesk_version/rustdesk-$restdesk_version-windows_$os_arch.zip -Outfile rustdesk.zip
Expand-Archive rustdesk.zip
cd rustdesk
Start .\rustdesk-$restdesk_version-putes.exe --silent-install
# 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
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force > null
Install-Module ps2exe -Force > null
$urlhandler_ps1 = @"
`$url_handler = `$args[0]
`$rustdesk_id = `$url_handler -creplace '(?s)^.*\:',''
Start-Process -FilePath '$env:ProgramFiles\RustDesk\rustdesk.exe' -ArgumentList "--connect `$rustdesk_id"
"@
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
Start-Sleep -s 20
# Cleanup Tempfiles
Remove-Item "$env:ProgramFiles\RustDesk\urlhandler.ps1" > null
cd $env:Temp
Remove-Item $env:Temp\rustdesk -Recurse > null
Remove-Item $env:Temp\rustdesk.zip > null
}
If ($EnableAudio) {
$Audio = 'Y'
} Else {
$Audio = 'N'
}
# Write config
$RustDesk2_toml = @"
rendezvous_server = '$WanIPReg'
nat_type = 1
serial = 0
[options]
custom-rendezvous-server = '$WanIPReg'
key = '$KeyReg'
relay-server = '$WanIPReg'
api-server = 'https://$WanIPReg'
enable-audio = '$Audio'
"@
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
$random_pass = (-join ((65..90) + (97..122) | Get-Random -Count $PasswordLength | % {[char]$_}))
Start "$env:ProgramFiles\RustDesk\RustDesk.exe" "--password $random_pass"
Start-Sleep -s 5
# Get RustDesk ID
If (!("$env:WinDir\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk.toml")) {
$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 {
$rustdesk_id = (Get-Content $env:WinDir\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk.toml | Where-Object { $_.Contains("id") })
$rustdesk_id = $rustdesk_id.Split("'")[1]
$rustdesk_pw = (Get-Content $env:WinDir\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk.toml | Where-Object { $_.Contains("password") })
$rustdesk_pw = $rustdesk_pw.Split("'")[1]
Write-Output "Config file found in windows service folder"
OutputIDandPW $rustdesk_id $rustdesk_pw
}
Start-Sleep -s 10
Stop-Process -Name RustDesk -Force > null
Start-Service -Name RustDesk > null