REM @echo off setlocal enabledelayedexpansion REM Detect if we have admin rights SET /A ADMIN=0 net session 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 SET /A ADMIN=1 IF %ADMIN% EQU 1 CALL %~dp0\..\conf\adm\conf.bat IF %ADMIN% NEQ 1 CALL %~dp0\..\conf\user\conf.bat SET /A WAIT=0 CALL %~dp0\..\lang\en.bat FOR /F "tokens=3" %%A IN ('reg query "HKLM\System\CurrentControlSet\Control\nls\Language" /v Installlanguage') DO SET LANG=%%A IF EXIST %~dp0\..\lang\%LANG%.bat CALL %~dp0\..\lang\%LANG%.bat SET watitle=%L_WINDOW_TITLE% SET wasig=%L_WINDOW_SIG% SET walabels=%L_BTN_PREV%;%L_BTN_NEXT%;%L_BTN_OK%;%L_BTN_CANCEL% SET wabmp=%SystemDrive%\FWSUpdates\assets\img\fws.bmp SET waico=%SystemDrive%\FWSUpdates\assets\img\fws.ico SET wabat=%TEMP%\fwsupdates_resp.bat :loop IF NOT "%1" == "loop" IF NOT %WAIT% EQU 0 goto :EOF timeout /t %WAIT% 1>NUL 2>NUL :begin SET /A WAIT=300 SET /A SYNC_IN_PROGRESS=0 SET /A RUN_ON_SHUTDOWN=0 REM Wait if a sync is running reg query "HKLM\Software\FWS\Updates" /v SyncInProgress 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 FOR /F "tokens=3" %%A IN ('reg query "HKLM\Software\FWS\Updates" /v SyncInProgress') DO SET /A SYNC_IN_PROGRESS=%%A IF %SYNC_IN_PROGRESS% EQU 1 ( IF "%1" == "loop" goto loop SET watext=%L_SYNC_ALREADY_IN_PROGRESS% start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH NOBACK NOCANCEL TB goto :EOF ) REM if updates are already scheduled for next shutdown, just quit now, there's no point in looping reg query "HKLM\Software\FWS\Updates\User" /v RunOnShutdown 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 FOR /F "tokens=3" %%A IN ('reg query "HKLM\Software\FWS\Updates\User" /v RunOnShutdown') DO SET /A RUN_ON_SHUTDOWN=%%A IF %RUN_ON_SHUTDOWN% EQU 0 ( reg query "HKLM\Software\FWS\Updates" /v RunOnShutdown 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 FOR /F "tokens=3" %%A IN ('reg query "HKLM\Software\FWS\Updates" /v RunOnShutdown') DO SET /A RUN_ON_SHUTDOWN=%%A ) IF %RUN_ON_SHUTDOWN% EQU 1 ( IF "%1" == "loop" goto :EOF IF %ADMIN% NEQ 1 ( SET watext=%L_ALREADY_SCHEDULED_ON_SHUTDOWN% start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH NOBACK NOCANCEL TB goto :EOF ) ) SET CHANGES=0 reg query "HKLM\Software\FWS\Updates" /v PendingChanges 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 FOR /F "tokens=3" %%A IN ('reg query "HKLM\Software\FWS\Updates" /v PendingChanges') DO SET /A CHANGES=%%A IF %CHANGES% LSS 1 IF %ADMIN% NEQ 1 ( IF "%1" == "loop" goto loop SET watext=%L_NO_UPDATE_AVAILABLE% %L_FOR_YOUR_SYSTEM%. start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH NOBACK NOCANCEL TB goto :EOF ) FOR /F "delims=" %%A in ('cscript /nologo %~dp0\now.vbs') DO SET /A NOW=%%A SET /A SINCE=%NOW% reg query "HKLM\Software\FWS\Updates" /v ChangesAvailableSince 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 FOR /F "tokens=3 delims= " %%A IN ('reg query "HKLM\Software\FWS\Updates" /v ChangesAvailableSince') DO SET /A SINCE=%%A REM Some wording changes if there's only 1 single change to apply IF %CHANGES% EQU 1 ( SET INTRO=1 %L_ONE_UPDATE_AVAILABLE% SET AVAILABLE_SINCE=%L_ONE_UPDATE_AVAILABLE_SINCE% ) ELSE ( SET INTRO=%CHANGES% %L_X_UPDATES_AVAILABLE% SET AVAILABLE_SINCE=%L_X_UPDATES_AVAILABLE_SINCE% ) REM Compute how many days left we can delay updates SET /A MAX=%SINCE%+%MAX_REPORT%*86400 SET /A AGE=%NOW%-%SINCE% SET /A AGE=%AGE%/86400 SET /A REMAINING=%MAX%-%NOW% SET /A REMAINING=%REMAINING%/86400 REM Non admin on RDP shouldn't see updates notif IF %ADMIN% NEQ 1 IF NOT "%SESSIONNAME%" == "Console" goto :EOF REM Check if we can delay updates SET /A CAN_REPORT=0 IF %NOW% LEQ %MAX% SET /A CAN_REPORT=1 IF %CHANGES% LSS 1 ( IF %ADMIN% EQU 1 ( SET watext=%L_NO_UPDATE_AVAILABLE% %L_FOR_YOUR_SYSTEM%. SET wainput= %L_CHECK_ONLINE_FOR_UPDATES% SET waoutnum=0 start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe NOBACK RB IF errorlevel 2 goto cancel_no_update IF errorlevel 1 goto previous IF !waoutnum! EQU 0 goto check ) ) ELSE ( IF %CAN_REPORT% EQU 1 ( SET watext=%INTRO% %L_FOR_YOUR_SYSTEM%.~~%L_YOU_CAN_SCHEDULE%.~~%L_INSTALL_FORCED_IN% %REMAINING% %L_DAYS% SET wainput= %L_SCHEDULE_ON_SHUTDOWN%; %L_REPORT%; %L_DISPLAY_AVAILABLE_UPDATES% IF %ADMIN% EQU 1 ( IF %RUN_ON_SHUTDOWN% NEQ 1 ( SET wainput= %L_SCHEDULE_ON_SHUTDOWN%; %L_REPORT%; %L_DISPLAY_AVAILABLE_UPDATES%; %L_INSTALL_NOW%; %L_CHECK_ONLINE_FOR_UPDATES% ) ELSE ( SET watext=%INTRO% %L_FOR_YOUR_SYSTEM%.~~%L_ALREADY_SCHEDULED_ON_SHUTDOWN%.~~%L_INSTALL_FORCED_IN% %REMAINING% %L_DAYS% SET wainput= %L_MAINTAIN_ON_SHUTDOWN%; %L_CANCEL_SCHEDULE_ON_SHUTDOWN%; %L_DISPLAY_AVAILABLE_UPDATES%; %L_INSTALL_NOW%; %L_CHECK_ONLINE_FOR_UPDATES% ) ) SET waoutnum=0 start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe NOBACK RB IF errorlevel 2 goto cancel IF errorlevel 1 goto previous CALL %wabat% IF !waoutnum! EQU 0 goto shutdown IF !waoutnum! EQU 1 goto later IF !waoutnum! EQU 2 goto display IF !waoutnum! EQU 3 goto now IF !waoutnum! EQU 4 goto check ) ELSE ( SET watext=%INTRO% %L_FOR_YOUR_SYSTEM%.~~%AVAILABLE_SINCE% %L_SINCE% %AGE% %L_DAYS%.~~%L_CANT_REPORT_ANYMORE% start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH TB goto :EOF ) ) goto :loop :cancel goto :later :cancel_no_update goto :EOF :previous goto :loop :check IF %ADMIN% NEQ 1 goto later REM We're checking for update, disable RUnOnShutdown so sync will happen reg delete "HKLM\Software\FWS\Updates" /v RunOnShutdown /f 1>NUL 2>NUL reg delete "HKLM\Software\FWS\Updates\User" /v RunOnShutdown /f 1>NUL 2>NUL SET watext=%L_CHECKING_UPDATES% start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe PB OPEN NOBACK NOCANCEL start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe PB UPDATE 10 CALL %~dp0\sync.bat start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe PB CLOSE goto begin :later reg del "HKLM\Software\FWS\Updates\User" /v RunOnShutdown /f 1>NUL 2>NUL IF %ADMIN% EQU 1 reg del "HKLM\Software\FWS\Updates" /v RunOnShutdown /f 1>NUL 2>NUL SET watext=%L_UPDATES_REPORTED%. start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH NOBACK TB SET /A WAIT=WAIT+10800 goto loop :display SET watext=%L_THESE_UPDATES_ARE_PENDING% FOR /F "tokens=3 delims= " %%A IN ('reg query "HKLM\Software\FWS\Updates" /v PendingChangesList') DO SET LIST=%%A SET wainput=%LIST:,=~% start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe NOBACK FT goto begin :shutdown reg add "HKLM\Software\FWS\Updates\User" /v RunOnShutdown /t REG_DWORD /d 1 /f SET watext=%L_UPDATES_SCHEDULED% %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH NOBACK TB goto :EOF :now IF %ADMIN% NEQ 1 goto later CALL %~dp0\wpkg_feedback.bat %CHANGES% SET watext=%L_UPDATES_FINISHED% start /w %SystemDrive%\FWSUpdates\bin\wizapp.exe FINISH NOBACK NOCANCEL TB goto :loop