diff --git a/rd_setup.ps1 b/rd_setup.ps1 index 1c5211d..6f8b79a 100644 --- a/rd_setup.ps1 +++ b/rd_setup.ps1 @@ -86,6 +86,42 @@ Write-Host " Downloading..." -ForegroundColor Gray Invoke-WebRequest -Uri $rdUrl -OutFile $rdPath -ErrorAction Stop Write-Host " Downloaded" -ForegroundColor Green +# Proveryaem est li uzhe ustanovlennyj RustDesk i udalyaem +$oldUninstallPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\rustdesk" +$oldVersion = $null +if (Test-Path $oldUninstallPath) { + $oldVersion = (Get-ItemProperty $oldUninstallPath).DisplayVersion +} + +if ($oldVersion) { + Write-Host " Old version detected: $oldVersion" -ForegroundColor Yellow + Write-Host " Removing old version..." -ForegroundColor Gray + + # Probuem cherez UninstallString + $uninstallStr = (Get-ItemProperty $oldUninstallPath).UninstallString + if ($uninstallStr) { + if ($uninstallStr -match '"(.+)"') { + $uninstallExe = $matches[1] + $uninstallArgs = '/S' + if ($uninstallStr -match '"(.+)"\s+(.+)') { + $uninstallExe = $matches[1] + $uninstallArgs = $matches[2] + } + Start-Process $uninstallExe -ArgumentList $uninstallArgs -Wait -NoNewWindow -ErrorAction SilentlyContinue + Start-Sleep -Seconds 3 + } + } + + # Takzhe cherez WMI + $oldApp = Get-WmiObject -Class Win32_Product -Filter "Name='RustDesk'" -ErrorAction SilentlyContinue + if ($oldApp) { + $oldApp.Uninstall() | Out-Null + Start-Sleep -Seconds 3 + } + + Write-Host " Old version removed" -ForegroundColor Green +} + Write-Host " Installing..." -ForegroundColor Gray $result = Start-Process $rdPath -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait -PassThru -NoNewWindow