Powershell script will now be able to automatically get the latest version from github

The function getLatest() returns an object containing the current version number and the current download link.

In addition, the parameter "-wait" had to be removed from Start-Process, as the current version (1.2.3) apparently never ends if the Rustdesk service is not ended manually. Instead, a start-sleep of 20 seconds was added.
This commit is contained in:
User35123
2024-01-19 15:17:24 +01:00
parent 775e355fc6
commit f81ba46944
3 changed files with 156 additions and 13 deletions
@@ -33,9 +33,55 @@ if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
}
}
# This function will return the latest version and download link as an object
function getLatest()
{
$Page = Invoke-WebRequest -Uri 'https://github.com/rustdesk/rustdesk/releases/latest' -UseBasicParsing
$HTML = New-Object -Com "HTMLFile"
try
{
$HTML.IHTMLDocument2_write($Page.Content)
}
catch
{
$src = [System.Text.Encoding]::Unicode.GetBytes($Page.Content)
$HTML.write($src)
}
# Current example link: https://github.com/rustdesk/rustdesk/releases/download/1.2.3/rustdesk-1.2.3-x86_64.exe
$Downloadlink = ($HTML.Links | Where {$_.href -match '(.)+\/rustdesk\/rustdesk\/releases\/download\/\d{1}.\d{1,2}.\d{1,2}(.{0,3})\/rustdesk(.)+x86_64.exe'} | select -first 1).href
# bugfix - sometimes you need to replace "about:"
$Downloadlink = $Downloadlink.Replace('about:', 'https://github.com')
$Version = "unknown"
if ($Downloadlink -match './rustdesk/rustdesk/releases/download/(?<content>.*)/rustdesk-(.)+x86_64.exe')
{
$Version = $matches['content']
}
if ($Version -eq "unknown" -or $Downloadlink -eq "")
{
Write-Output "ERROR: Version or download link not found."
Exit
}
# Create object to return
$Result = New-Object PSObject -Property
@{
Version = $Version
Downloadlink = $Downloadlink
}
return($Result)
}
$RustDeskOnGitHub = getLatest
$rdver = ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk\").Version)
if ($rdver -eq "1.2.3")
if ($rdver -eq $RustDeskOnGitHub.Version)
{
Write-Output "RustDesk $rdver is the newest version"
Exit
@@ -48,8 +94,9 @@ if (!(Test-Path C:\Temp))
cd C:\Temp
Invoke-WebRequest "https://github.com/rustdesk/rustdesk/releases/download/1.2.3/rustdesk-1.2.3-x86_64.exe" -Outfile "rustdesk.exe"
Start-Process .\rustdesk.exe --silent-install -wait
Invoke-WebRequest $RustDeskOnGitHub.Downloadlink -Outfile "rustdesk.exe"
Start-Process .\rustdesk.exe --silent-install
Start-Sleep -seconds 20
$ServiceName = 'Rustdesk'
$arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
@@ -58,7 +105,7 @@ if ($arrService -eq $null)
{
Write-Output "Installing service"
cd $env:ProgramFiles\RustDesk
Start-Process .\rustdesk.exe --install-service -wait -Verbose
Start-Process .\rustdesk.exe --install-service
Start-Sleep -seconds 20
}