102 lines
4.6 KiB
PowerShell
102 lines
4.6 KiB
PowerShell
# ScoutIT Remote Support (RustDesk) - Standalone Install Script
|
|
$ErrorActionPreference = 'SilentlyContinue'
|
|
|
|
# ── Config ────────────────────────────────────────────────────────────────────
|
|
$rustdeskMsi = 'estudio-scoutit-remotesupport.msi'
|
|
$rustdeskDl = 'https://scoutit.help/estudio-rust'
|
|
$rustdeskInstallDir = 'C:\Program Files\ScoutIT-RemoteSupport'
|
|
$rustdeskService = 'ScoutIT-RemoteSupport'
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
# ── Check if already installed ────────────────────────────────────────────────
|
|
$svcCheck = Get-Service -Name $rustdeskService -ErrorAction SilentlyContinue
|
|
if ($null -ne $svcCheck) {
|
|
Write-Host "ScoutIT Remote Support is already installed. Exiting."
|
|
exit 0
|
|
}
|
|
|
|
# ── Download ──────────────────────────────────────────────────────────────────
|
|
$msiPath = "$env:TMP\$rustdeskMsi"
|
|
Write-Host "Downloading ScoutIT Remote Support client..."
|
|
Try {
|
|
Invoke-WebRequest -Uri $rustdeskDl -OutFile $msiPath
|
|
}
|
|
Catch {
|
|
Write-Error "Download failed: $($_.Exception.Message)"
|
|
exit 1
|
|
}
|
|
|
|
# ── Silent MSI install ────────────────────────────────────────────────────────
|
|
Write-Host "Installing ScoutIT Remote Support client silently..."
|
|
Try {
|
|
Start-Process -FilePath "msiexec.exe" `
|
|
-ArgumentList "/i `"$msiPath`" /qn /norestart CREATEDESKTOPSHORTCUTS=`"N`" INSTALLPRINTER=`"N`"" `
|
|
-Wait
|
|
Start-Sleep -Seconds 10
|
|
}
|
|
Catch {
|
|
Write-Error "MSI install failed: $($_.Exception.Message)"
|
|
exit 1
|
|
}
|
|
Finally {
|
|
if (Test-Path $msiPath) { Remove-Item -Path $msiPath -Force }
|
|
}
|
|
|
|
# ── Locate the installed exe ──────────────────────────────────────────────────
|
|
$rustdeskExe = "$rustdeskInstallDir\$($rustdeskMsi -replace '\.msi$', '.exe')"
|
|
if (-not (Test-Path $rustdeskExe)) {
|
|
Write-Host "Searching for RustDesk exe in Program Files..."
|
|
$found = Get-ChildItem 'C:\Program Files' -Recurse -Filter '*.exe' -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Name -match 'rustdesk|scoutit|remotesupport' } |
|
|
Select-Object -First 1
|
|
if ($found) {
|
|
$rustdeskExe = $found.FullName
|
|
Write-Host "Found exe at: $rustdeskExe"
|
|
} else {
|
|
Write-Error "Could not locate RustDesk exe after install."
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
$exeDir = Split-Path $rustdeskExe
|
|
|
|
# ── Install service if not present ────────────────────────────────────────────
|
|
$svc = Get-Service -Name $rustdeskService -ErrorAction SilentlyContinue
|
|
if ($null -eq $svc) {
|
|
Write-Host "Registering ScoutIT Remote Support service..."
|
|
Start-Process -FilePath $rustdeskExe -ArgumentList '--install-service' -Wait
|
|
Start-Sleep -Seconds 20
|
|
$svc = Get-Service -Name $rustdeskService -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# ── Ensure service is running ─────────────────────────────────────────────────
|
|
if ($null -ne $svc) {
|
|
$attempts = 0
|
|
while ($svc.Status -ne 'Running' -and $attempts -lt 5) {
|
|
Write-Host "Starting ScoutIT Remote Support service (attempt $($attempts + 1))..."
|
|
Start-Service -Name $rustdeskService -ErrorAction SilentlyContinue
|
|
Start-Sleep -Seconds 5
|
|
$svc.Refresh()
|
|
$attempts++
|
|
}
|
|
if ($svc.Status -eq 'Running') {
|
|
Write-Host "ScoutIT Remote Support service is running."
|
|
} else {
|
|
Write-Warning "Service did not reach Running state after $attempts attempts."
|
|
}
|
|
} else {
|
|
Write-Warning "Service '$rustdeskService' not found after install."
|
|
}
|
|
|
|
# ── Output RustDesk ID ────────────────────────────────────────────────────────
|
|
Push-Location $exeDir
|
|
$rustdeskId = & $rustdeskExe --get-id 2>&1
|
|
Pop-Location
|
|
|
|
Write-Output "................................................."
|
|
Write-Output "ScoutIT Remote Support ID: $rustdeskId"
|
|
Write-Output "................................................."
|
|
|
|
exit 0
|