@echo off setlocal enabledelayedexpansion :: ============================== :: CONFIG :: ============================== set "FileName=VNPT-CA.Plugin_Office_Setup.1.0.5.0" set "DesktopPath=%UserProfile%\Desktop" set "ZipFilePath=%DesktopPath%\%FileName%.zip" set "ExtractPath=%DesktopPath%" set "DownloadUrl=https://github.com/tankiem/TCT_CKS/releases/latest/download/%FileName%.zip" :: ============================== :: DOWNLOAD :: ============================== echo. echo ===================================== echo [1/4] DOWNLOADING... echo ===================================== curl -L --fail --retry 3 --retry-delay 2 ^ -o "%ZipFilePath%" "%DownloadUrl%" if not exist "%ZipFilePath%" ( echo [X] Download FAILED! pause exit /b 1 ) echo [+] Download success! :: ============================== :: EXTRACT :: ============================== echo. echo ===================================== echo [2/4] EXTRACTING... echo ===================================== powershell -NoProfile -Command ^ "Expand-Archive -Path '%ZipFilePath%' -DestinationPath '%ExtractPath%' -Force" if errorlevel 1 ( echo [X] Extract FAILED! pause exit /b 1 ) echo [+] Extract success! :: ============================== :: FIND INSTALLER (SMART) :: ============================== echo. echo ===================================== echo [3/4] FINDING INSTALLER... echo ===================================== set "ExePath=" :: Lấy file mới nhất theo thời gian for /f "delims=" %%i in ('dir "%DesktopPath%\VNPT-CA*.exe" /b /a-d /o-d 2^>nul') do ( set "ExePath=%DesktopPath%\%%i" goto found_exe ) :found_exe if not defined ExePath ( echo [X] Installer not found on Desktop! pause goto cleanup ) echo [+] Found: !ExePath! :: ============================== :: INSTALL :: ============================== echo. echo ===================================== echo [4/4] INSTALLING... echo ===================================== start "" /wait "!ExePath!" /silent /FORCECLOSEAPPLICATIONS if errorlevel 1 ( echo [!] Installer returned error (may still installed) ) else ( echo [+] Install completed! ) :: ============================== :: CLEANUP :: ============================== :cleanup echo. echo ===================================== echo CLEANING... echo ===================================== if exist "%ZipFilePath%" del /f /q "%ZipFilePath%" echo [+] Done! pause endlocal