2022-08-03 00:59:40 +02:00
$ErrorActionPreference = 'silentlycontinue'
2022-08-13 23:45:20 +02:00
# Requires -RunAsAdministrator
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
If ( ! ( test-path " c:\temp " ) ) {
2022-08-09 16:16:19 +02:00
New-Item -ItemType Directory -Force -Path " c:\temp " > null
2022-08-03 00:59:40 +02:00
}
cd c: \ temp
If ( ! ( test-path " C:\Program Files\Rustdesk\RustDesk.exe " ) ) {
cd c: \ temp
Invoke-WebRequest https : / / github . com / rustdesk / rustdesk / releases / download / 1.1 . 9 / rustdesk - 1.1 . 9 -windows_x64 . zip -Outfile rustdesk . zip
expand-archive rustdesk . zip
cd rustdesk
start . \ rustdesk - 1.1 . 9 -putes . exe - -silent -install
2022-08-04 01:22:35 +02:00
# Set URL Handler
2022-08-09 16:16:19 +02:00
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
Set-ItemProperty -Path " HKLM:\SOFTWARE\Classes\RustDesk\shell\open\command " -Name " (Default) " -Value '"C:\Program Files\RustDesk\RustDeskURLLauncher.exe" "%1"' > null
New-Item " C:\Program Files\RustDesk\urlhandler.ps1 " > null
Set-Content " C:\Program Files\RustDesk\urlhandler.ps1 " " `$ url_handler = `$ args[0] `n `$ rustdesk_id = `$ url_handler -creplace '(?s)^.*\:','' `n Start-Process -FilePath 'C:\Program Files\RustDesk\rustdesk.exe' -ArgumentList "" --connect `$ rustdesk_id "" " > null
Install-PackageProvider -Name NuGet -MinimumVersion 2.8 . 5 . 201 -Force > null
Install-Module ps2exe -Force > null
Invoke-ps2exe " C:\Program Files\RustDesk\urlhandler.ps1 " " C:\Program Files\RustDesk\RustDeskURLLauncher.exe " > null
Remove-Item " C:\Program Files\RustDesk\urlhandler.ps1 " > null
2022-08-04 01:22:35 +02:00
2022-08-05 12:51:15 +02:00
Start-sleep -s 20
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-03 00:59:40 +02:00
$username = ( ( Get-WMIObject -ClassName Win32_ComputerSystem ) . Username ) . Split ( '\' ) [ 1 ]
New-Item C: \ Users \ $username \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml
2022-08-09 01:02:25 +02:00
Set-Content C: \ Users \ $username \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml " rendezvous_server = 'wanipreg' `n nat_type = 1 `n serial = 0 `n `n [options] `n custom-rendezvous-server = 'wanipreg' `n key = 'keyreg' `n relay-server = 'wanipreg' `n api-server = 'https://wanipreg' "
2022-08-03 00:59:40 +02:00
New-Item C: \ Windows \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml
2022-08-09 01:02:25 +02:00
Set-Content C: \ Windows \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk2 . toml " rendezvous_server = 'wanipreg' `n nat_type = 1 `n serial = 0 `n `n [options] `n custom-rendezvous-server = 'wanipreg' `n key = 'keyreg' `n relay-server = 'wanipreg' `n api-server = 'https://wanipreg' "
2022-08-03 00:59:40 +02:00
2022-08-09 01:02:25 +02:00
$rdpass = ( -join ( ( 65 . .90 ) + ( 97 . .122 ) | Get-Random -Count 8 | % { [ char ] $_ } ) )
start " C:\Program Files\RustDesk\RustDesk.exe " " --password $rdpass "
2022-08-03 00:59:40 +02:00
2022-08-09 16:16:19 +02:00
Start-sleep -s 5
2022-08-03 00:59:40 +02:00
# Get RustDesk ID
2022-08-09 01:05:28 +02:00
2022-08-09 16:16:19 +02:00
If ( ! ( " C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk.toml " ) ) {
2022-08-03 00:59:40 +02:00
$username = ( ( Get-WMIObject -ClassName Win32_ComputerSystem ) . Username ) . Split ( '\' ) [ 1 ]
$rustid = ( Get-content C: \ Users \ $username \ AppData \ Roaming \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " id " ) } )
$rustid = $rustid . Split ( " ' " ) [ 1 ]
$rustpword = ( Get-content C: \ Users \ $username \ AppData \ Roaming \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " password " ) } )
$rustpword = $rustpword . Split ( " ' " ) [ 1 ]
Write-output " $rustid "
Write-output " $rustpword "
2022-08-09 16:16:19 +02:00
Write-output " Config file found in user folder "
}
else {
2022-08-03 00:59:40 +02:00
$rustid = ( Get-content C: \ Windows \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " id " ) } )
$rustid = $rustid . Split ( " ' " ) [ 1 ]
2022-08-09 01:05:28 +02:00
2022-08-03 00:59:40 +02:00
$rustpword = ( Get-content C: \ Windows \ ServiceProfiles \ LocalService \ AppData \ Roaming \ RustDesk \ config \ RustDesk . toml | Where-Object { $_ . Contains ( " password " ) } )
$rustpword = $rustpword . Split ( " ' " ) [ 1 ]
Write-output " $rustid "
Write-output " $rustpword "
2022-08-09 16:16:19 +02:00
Write-output " Config file found in windows service folder "
}
2022-08-03 00:59:40 +02:00
Start-sleep -s 10
2022-08-09 16:16:19 +02:00
taskkill / IM " rustdesk.exe " / F > null
net start rustdesk > null