@echo off
chcp 65001 >nul
setlocal
title GRIS - vzdialená podpora - inštalácia
rem GRIS - inštalácia vzdialenej podpory (RustDesk 1.5.0 ako služba).
rem Spustite dvojklikom; vypýta si práva správcu a všetko nastaví.

fltmc >nul 2>&1
if errorlevel 1 goto elevate

echo.
echo  GRIS - vzdialená podpora - inštalácia
echo  -------------------------------------
echo  Prosím, nezatvárajte okno, kým sa nezobrazí krok 4/4 (zvyčajne do minúty).
echo.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; $Url = 'https://gris.grandcom.sk/remote/stiahnut/trvale?t=se3cqm2blsr9'; $File = 'rustdesk--QfikjczxmYy0WcjNTZz9CZy9SawF2LrNnLt92Yk5WYydmLzlmcn9yL6MHc0RHaiojIpBXYiwiI9AzY49kQBNjMXBlbFN2b1I3drRzcHlkURlDbZl0az92bpJnNFNXZNN2Q0wkI6ISeltmIsIyaz5SbvNGZuFmcn5ycpJ3ZiojI0N3boJye.exe'; $Config = 'QfikjczxmYy0WcjNTZz9CZy9SawF2LrNnLt92Yk5WYydmLzlmcn9yL6MHc0RHaiojIpBXYiwiI9AzY49kQBNjMXBlbFN2b1I3drRzcHlkURlDbZl0az92bpJnNFNXZNN2Q0wkI6ISeltmIsIyaz5SbvNGZuFmcn5ycpJ3ZiojI0N3boJye'; $Password = 'sxca5ChDqi6ApZqk'; $Installed = Join-Path $env:ProgramFiles 'RustDesk\rustdesk.exe'; $New = $false; $Code = ''; function RdRun([string[]]$A) { $script:RdOut = ''; $script:RdExit = $null; $I = New-Object System.Diagnostics.ProcessStartInfo $Installed; $I.Arguments = ($A | ForEach-Object { [char]34 + $_ + [char]34 }) -join ' '; $I.WorkingDirectory = Split-Path $Installed; $I.UseShellExecute = $false; $I.CreateNoWindow = $true; $I.RedirectStandardOutput = $true; $I.RedirectStandardError = $true; $Q = [System.Diagnostics.Process]::Start($I); $O = $Q.StandardOutput.ReadToEndAsync(); $E = $Q.StandardError.ReadToEndAsync(); if (-not $Q.WaitForExit(60000)) { try { $Q.Kill() } catch { }; return $false }; $script:RdExit = $Q.ExitCode; $T = ''; if ($O.Wait(3000)) { $T += $O.Result }; if ($E.Wait(3000)) { $T += ' ' + $E.Result }; $script:RdOut = ($T -replace '\s+', ' ').Trim(); return $true }; $Res = 'already'; $Rep = 'https://gris.grandcom.sk/api/rd/se3cqm2blsr9/gris-install/9dii3vl4lffi1aimihqldfixyiqdlddb'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; function Rep([string]$R, [string]$M) { try { Invoke-RestMethod -UseBasicParsing -Method Post -Uri $Rep -Body @{ r = $R; m = $M } -TimeoutSec 30 | Out-Null } catch { } }; try { if (Test-Path $Installed) { Write-Host '[1/4] [2/4] Program už je nainštalovaný.' -ForegroundColor Cyan }; if (-not (Test-Path $Installed)) { $Res = 'installed'; Write-Host '[1/4] Sťahujem program...' -ForegroundColor Cyan; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $Tmp = Join-Path $env:TEMP $File; Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Tmp; Write-Host '[2/4] Inštalujem službu...' -ForegroundColor Cyan; $P = Start-Process -FilePath $Tmp -ArgumentList '--silent-install' -PassThru; $null = $P.Handle; $New = $true; for ($i = 0; $i -lt 60 -and -not ((Test-Path $Installed) -and ((Get-Service -Name RustDesk -ErrorAction SilentlyContinue).Status -eq 'Running')); $i++) { Start-Sleep -Seconds 2 }; if (-not (Test-Path $Installed)) { $Code = $(if ($P.HasExited) { 'exit' + $P.ExitCode } else { 'running' }); throw ('RustDesk sa nenainstaloval (chyba rustdesk.exe, ' + $Code + ')') }; Start-Sleep -Seconds 5; try { $SvcPid = (Get-CimInstance -ClassName Win32_Service -Filter 'Name=''RustDesk''').ProcessId } catch { $SvcPid = 0 }; if (-not $P.HasExited) { Stop-Process -Id $P.Id -Force -ErrorAction SilentlyContinue }; Get-Process -Name rustdesk -ErrorAction SilentlyContinue | Where-Object { $_.Id -ne $SvcPid } | Stop-Process -Force -ErrorAction SilentlyContinue; Remove-Item $Tmp -Force -ErrorAction SilentlyContinue }; if (-not (Test-Path $Installed)) { throw 'RustDesk sa nenainstaloval (chyba rustdesk.exe)' }; Write-Host '[3/4] Nastavujem pripojenie a heslo...' -ForegroundColor Cyan; for ($i = 0; $i -lt 15 -and -not (Get-CimInstance -ClassName Win32_Process -Filter 'Name=''rustdesk.exe''' -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like '*--server*' }); $i++) { Start-Sleep -Seconds 2 }; if (-not (RdRun @('--config', $Config))) { $Code = 'hang'; throw 'rustdesk --config neskoncil do 60 s' }; if ($RdExit -ne 0) { Write-Host ('GRIS RustDesk: --config kod ' + $RdExit + ' ' + $RdOut) }; if ($Password -ne '' -and -not (RdRun @('--password', $Password))) { $Code = 'hang'; throw 'rustdesk --password neskoncil do 60 s' }; if ($New) { Restart-Service -Name RustDesk -Force -ErrorAction SilentlyContinue }; Rep $Res ''; Write-Host '[4/4] Hotovo - vzdialená podpora je nainštalovaná, technik sa vám ozve.' -ForegroundColor Green } catch { Rep 'fail' $_.Exception.Message; $C = ''; if ($_.Exception.Response) { try { $C = ' (http ' + [int]$_.Exception.Response.StatusCode + ')' } catch { } }; Write-Host ('CHYBA: ' + $_.Exception.Message + $C) -ForegroundColor Red; Write-Host 'Inštalácia sa nepodarila - zavolajte prosím technikovi.' -ForegroundColor Red; exit 1 }"
if errorlevel 1 goto failed
echo.
echo  Okno môžete zavrieť.
pause >nul
exit /b 0

:failed
echo.
echo Stlačte ľubovoľný kláves...
pause >nul
exit /b 1

:elevate
echo  GRIS: potrebné sú práva správcu - v okne Windows potvrďte „Áno“...
set "GRIS_SELF=%~f0"
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath $env:GRIS_SELF -Verb RunAs" >nul 2>&1
if errorlevel 1 goto noadmin
exit /b 0

:noadmin
powershell.exe -NoProfile -Command "Write-Host 'CHYBA: bez práv správcu sa program nenainštaluje.' -ForegroundColor Red"
echo Stlačte ľubovoľný kláves...
pause >nul
exit /b 1
