diff --git a/1-estudio-Install-TacticalRMM-and-RustDesk.ps1 b/1-estudio-Install-TacticalRMM-and-RustDesk.ps1 index 0d8451d..7792415 100644 --- a/1-estudio-Install-TacticalRMM-and-RustDesk.ps1 +++ b/1-estudio-Install-TacticalRMM-and-RustDesk.ps1 @@ -175,25 +175,36 @@ If (Get-Service $serviceName -ErrorAction SilentlyContinue) { Catch { # pass } - Try { - Write-Host "Downloading TacticalRMM agent..." - Start-BitsTransfer -Source $downloadlink -Destination "$OutPath\$output" -ErrorAction Stop - Write-Host "Download complete." - Start-Process -FilePath "$OutPath\$output" -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES' -Wait - Write-Host "Extracting..." + $X = 0 + do { + Write-Output "Waiting for network" Start-Sleep -s 5 - Start-Process -FilePath "C:\Program Files\TacticalAgent\tacticalrmm.exe" -ArgumentList $installArgs -Wait + $X += 1 + } until (($connectresult = Test-NetConnection $apilink[2] -Port 443 | Where-Object { $_.TcpTestSucceeded }) -or $X -eq 3) - # ── Install RustDesk after Tactical RMM ── - Install-RustDesk + if ($connectresult.TcpTestSucceeded -eq $true) { + Try { + Invoke-WebRequest -Uri $downloadlink -OutFile "$OutPath\$output" + Start-Process -FilePath "$OutPath\$output" -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES' -Wait + Write-Host "Extracting..." + Start-Sleep -s 5 + Start-Process -FilePath "C:\Program Files\TacticalAgent\tacticalrmm.exe" -ArgumentList $installArgs -Wait - exit 0 - } - Catch { - Write-Warning "TacticalRMM install failed: $($_.Exception.Message)" - exit 1 - } - Finally { - if (Test-Path "$OutPath\$output") { Remove-Item -Path "$OutPath\$output" -Force } + # ── Install RustDesk after Tactical RMM ── + Install-RustDesk + + exit 0 + } + Catch { + $ErrorMessage = $_.Exception.Message + $FailedItem = $_.Exception.ItemName + Write-Error -Message "$ErrorMessage $FailedItem" + exit 1 + } + Finally { + if (Test-Path "$OutPath\$output") { Remove-Item -Path "$OutPath\$output" -Force } + } + } else { + Write-Output "Unable to connect to server" } }