@echo off setlocal EnableExtensions EnableDelayedExpansion chcp 65001 >nul title RAM Nuvem - Instalador RustDesk REM ========================================================= REM Cores (via prompt ANSI - Windows 10/11) REM ========================================================= for /f %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a" set "CYAN=%ESC%[96m" set "GREEN=%ESC%[92m" set "YELLOW=%ESC%[93m" set "RED=%ESC%[91m" set "BOLD=%ESC%[1m" set "RESET=%ESC%[0m" REM ========================================================= REM Auto-elevar para administrador REM (RunAs eleva o MESMO usuario -> %APPDATA% continua o do usuario) REM ========================================================= net session >nul 2>&1 if %errorlevel% neq 0 ( powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs" exit /b ) cls echo %CYAN%%BOLD% echo ============================================================ echo RAM NUVEM ^|^| Instalador e Configurador RustDesk echo ============================================================ echo %RESET% echo Este assistente vai preparar o acesso remoto no seu computador. echo Por favor, aguarde ate a finalizacao. echo. REM ========================================================= REM Caminhos REM ========================================================= set "CONFIG_DIR=%APPDATA%\RustDesk\config" set "CONFIG_FILE=%CONFIG_DIR%\RustDesk2.toml" set "CONFIG_FILE_DEFAULT=%CONFIG_DIR%\RustDesk_default.toml" set "CONFIG_FILE_LOCAL=%CONFIG_DIR%\RustDesk_local.toml" set "TEMP_DIR=%TEMP%\rustdesk_ram" set "MSI_FILE=%TEMP_DIR%\rustdesk.msi" set "INSTALL_LOG=%TEMP_DIR%\install.log" set "RUSTDESK_EXE=" echo %BOLD%[1/4]%RESET% Verificando se o RustDesk ja esta instalado... call :find_rustdesk if defined RUSTDESK_EXE ( echo %GREEN%OK%RESET% - RustDesk ja esta instalado neste computador. ) else ( echo Nao encontrado - sera instalado automaticamente. ) echo. REM ========================================================= REM Instalar RustDesk via MSI se nao estiver instalado REM ========================================================= if not defined RUSTDESK_EXE ( echo %BOLD%[2/4]%RESET% Baixando a versao mais recente do RustDesk... if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%" powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$ErrorActionPreference='Stop';" ^ "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ^ "$release=Invoke-RestMethod 'https://api.github.com/repos/rustdesk/rustdesk/releases/latest';" ^ "$asset=$release.assets | Where-Object { $_.name -match 'x86_64.*\.msi$' } | Select-Object -First 1;" ^ "if (-not $asset) { throw 'MSI x86_64 nao encontrado no GitHub releases.' };" ^ "$url=$asset.browser_download_url;" ^ "$wc=New-Object System.Net.WebClient;" ^ "$global:pct=0; $global:finished=$false; $global:dlError=$null;" ^ "Register-ObjectEvent -InputObject $wc -EventName DownloadProgressChanged -SourceIdentifier dlProgress -Action { $global:pct=$Event.SourceEventArgs.ProgressPercentage } | Out-Null;" ^ "Register-ObjectEvent -InputObject $wc -EventName DownloadFileCompleted -SourceIdentifier dlDone -Action { if ($Event.SourceEventArgs.Error) { $global:dlError=$Event.SourceEventArgs.Error }; $global:finished=$true } | Out-Null;" ^ "$wc.DownloadFileAsync([Uri]$url,'%MSI_FILE%');" ^ "$ticks=0;" ^ "while(-not $global:finished){ $bar=('#'*[Math]::Floor($global:pct/5)).PadRight(20,'.'); Write-Host ([char]13+(' [{0}] {1}%% ' -f $bar,$global:pct)) -NoNewline; Start-Sleep -Milliseconds 150; $ticks++; if ($ticks -gt 800) { $wc.CancelAsync(); $global:dlError='Tempo limite de download excedido (120s).'; break } };" ^ "Unregister-Event -SourceIdentifier dlProgress -ErrorAction SilentlyContinue;" ^ "Unregister-Event -SourceIdentifier dlDone -ErrorAction SilentlyContinue;" ^ "$wc.Dispose();" ^ "if ($global:dlError) { if (Test-Path '%MSI_FILE%') { Remove-Item '%MSI_FILE%' -Force -ErrorAction SilentlyContinue }; throw $global:dlError };" ^ "Write-Host ([char]13+(' [{0}] 100%% ' -f ('#'*20)));" if not exist "%MSI_FILE%" ( echo. echo %RED%ERRO:%RESET% nao foi possivel baixar o instalador do RustDesk. echo Verifique sua conexao com a internet e tente novamente. echo. pause exit /b 1 ) echo %GREEN%OK%RESET% - Download concluido. echo. echo %BOLD%[3/4]%RESET% Instalando o RustDesk, aguarde... msiexec /i "%MSI_FILE%" /qn /norestart /L*v "%INSTALL_LOG%" set "MSI_RC=!errorlevel!" REM MSI_RC capturado com !...! (delayed): %errorlevel% expandiria em parse time neste bloco REM 3010 = sucesso, porem requer reinicio - nao e falha if !MSI_RC! neq 0 if !MSI_RC! neq 3010 ( echo. echo %RED%ERRO:%RESET% a instalacao falhou ^(codigo !MSI_RC!^). echo Verifique o log em: %INSTALL_LOG% echo. pause exit /b 1 ) REM Aguardar e localizar o executavel (ate ~30s; o MSI pode demorar a materializar o arquivo) for /l %%s in (1,1,30) do ( if not defined RUSTDESK_EXE ( call :find_rustdesk if not defined RUSTDESK_EXE timeout /t 1 /nobreak >nul ) ) if not defined RUSTDESK_EXE ( echo. echo %RED%ERRO:%RESET% RustDesk foi instalado ^(codigo !MSI_RC!^), mas o executavel nao foi localizado. echo Log da instalacao: %INSTALL_LOG% echo. pause exit /b 1 ) echo %GREEN%OK%RESET% - RustDesk instalado com sucesso. echo. ) else ( echo %BOLD%[2/4]%RESET% Download - dispensado ^(ja instalado^). echo %BOLD%[3/4]%RESET% Instalacao - dispensada ^(ja instalado^). echo. ) REM ========================================================= REM Parar RustDesk antes de aplicar config REM ========================================================= taskkill /F /IM rustdesk.exe >nul 2>&1 REM ========================================================= REM Criar arquivo RustDesk2.toml REM ========================================================= echo %BOLD%[4/4]%RESET% Aplicando as configuracoes do servidor RAM Nuvem... if not exist "%CONFIG_DIR%" mkdir "%CONFIG_DIR%" ( echo rendezvous_server = 'desk.ramnuvem.com:21116' echo. echo [options] echo relay-server = 'desk.ramnuvem.com' echo key = 'sbccZ612PSiDPBLR6lPhpVUoNr7OInBeuAToqPKBAQQ=' echo allow-remote-config-modification = 'Y' echo custom-rendezvous-server = 'desk.ramnuvem.com' ) > "%CONFIG_FILE%" if exist "%CONFIG_FILE%" ( echo %GREEN%OK%RESET% - Configuracao aplicada. ) else ( echo %RED%ERRO:%RESET% nao foi possivel criar o arquivo de configuracao. pause exit /b 1 ) ( echo [options] echo view_style = 'adaptive' ) > "%CONFIG_FILE_DEFAULT%" ( echo [options] echo enable-check-update = 'N' ) > "%CONFIG_FILE_LOCAL%" echo. REM ========================================================= REM Forcar RustDesk sempre rodar como administrador REM (AppCompatFlags Layers - vale p/ qualquer atalho/lançador, REM nao so o .lnk criado pelo MSI) REM ========================================================= reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%RUSTDESK_EXE%" /t REG_SZ /d "RUNASADMIN" /f >nul 2>&1 reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%RUSTDESK_EXE%" /t REG_SZ /d "RUNASADMIN" /f >nul 2>&1 REM ========================================================= REM Marcar atalhos (.lnk) do RustDesk com "Executar como REM administrador" (bit RunAsAdmin no header do .lnk, offset REM 0x15 / flag 0x20 - nao existe flag de batch p/ isso) REM ========================================================= for %%D in ("%PUBLIC%\Desktop" "%USERPROFILE%\Desktop" "%ProgramData%\Microsoft\Windows\Start Menu\Programs" "%APPDATA%\Microsoft\Windows\Start Menu\Programs") do ( if exist "%%~D" ( for /r "%%~D" %%F in (*RustDesk*.lnk) do ( powershell -NoProfile -ExecutionPolicy Bypass -Command "$p='%%F'; $b=[IO.File]::ReadAllBytes($p); $b[0x15]=$b[0x15] -bor 0x20; [IO.File]::WriteAllBytes($p,$b)" >nul 2>&1 ) ) ) REM ========================================================= REM Renomear atalho da area de trabalho REM ========================================================= for %%D in ("%PUBLIC%\Desktop" "%USERPROFILE%\Desktop") do ( if exist "%%~D\RustDesk.lnk" ren "%%~D\RustDesk.lnk" "RAM Acesso Remoto.lnk" ) REM ========================================================= REM Limpeza dos arquivos temporarios REM ========================================================= if exist "%TEMP_DIR%" rd /s /q "%TEMP_DIR%" >nul 2>&1 echo %GREEN%%BOLD% echo ============================================================ echo Instalacao concluida com sucesso! echo ============================================================ echo %RESET% endlocal exit /b 0 REM ========================================================= REM Subrotina: localizar rustdesk.exe REM Ordem: Program Files -> Program Files(x86) -> registro -> PATH REM ========================================================= :find_rustdesk if exist "%ProgramFiles%\RustDesk\rustdesk.exe" ( set "RUSTDESK_EXE=%ProgramFiles%\RustDesk\rustdesk.exe" goto :eof ) if exist "%ProgramFiles(x86)%\RustDesk\rustdesk.exe" ( set "RUSTDESK_EXE=%ProgramFiles(x86)%\RustDesk\rustdesk.exe" goto :eof ) for /f "tokens=2,*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk" /v InstallLocation 2^>nul ^| find "InstallLocation"') do ( if exist "%%~b\rustdesk.exe" set "RUSTDESK_EXE=%%~b\rustdesk.exe" ) if defined RUSTDESK_EXE goto :eof for /f "delims=" %%i in ('where rustdesk.exe 2^>nul') do ( if not defined RUSTDESK_EXE set "RUSTDESK_EXE=%%i" ) goto :eof