how to add progress bar to bat file

Discussion in 'Scripting' started by The_Guardian, Sep 6, 2012.

  1. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    #1 The_Guardian, Sep 6, 2012
    Last edited: Sep 6, 2012
    I would like to add a progress bar or indicator to my bat file that installs msu's. I have found one online but dont know how to add it....keeps saying "missing operand" which I dont understand. Any help would be great. Here is example of bat file....
    Here is the progress bar I found online....
    What I would like to do is do a overall progress bar for the Title area and then do a progress bar showing individual file installation progress in the area of echo Installing %%A. I just dont know where to use this progress bar scripting in my bat file. Any help would be great. Thanks in adv. and also Thanks to rholt for the progress bar scripting.
     
  2. searchengine

    searchengine Guest

    #2 searchengine, Sep 8, 2012
    Last edited by a moderator: Apr 20, 2017
    @cerberus8855...

    It's not a realtime 'progressbar'... it's a workaround type of progressbar, that you need to instruct % to display during execution of your main .cmd file.

    RED = % you define between actions
    (in this example between 'ping' cmds)

    save code as Example.cmd; and run to see progress in operation
    Code:
    @echo off
    
    call :progress 0
    ping -n 5 127.0.0.1 >nul
    call :progress 5
    ping -n 5 127.0.0.1 >nul
    call :progress 10
    ping -n 5 127.0.0.1 >nul
    call :progress 15
    ping -n 5 127.0.0.1 >nul
    call :progress 20
    ping -n 5 127.0.0.1 >nul
    call :progress 25
    ping -n 5 127.0.0.1 >nul
    call :progress 30
    ping -n 5 127.0.0.1 >nul
    call :progress 35
    ping -n 5 127.0.0.1 >nul
    call :progress 40
    ping -n 5 127.0.0.1 >nul
    EXIT
    
    :progress
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET ProgressPercent=%1
    SET /A NumBars=%ProgressPercent%/2
    SET /A NumSpaces=50-%NumBars%
    SET Meter=
    FOR /L %%A IN (%NumBars%,-1,1) DO SET Meter=!Meter!I
    FOR /L %%A IN (%NumSpaces%,-1,1) DO SET Meter=!Meter! 
    TITLE Progress:  [%Meter%]  %ProgressPercent%%%
    ENDLOCAL
     
  3. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    Thank you for explaining.
     
  4. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #4 Dos_Probie, Sep 12, 2012
    Last edited by a moderator: Apr 20, 2017
    Hey Cerberus,
    The Progress bar in the taskbar is a nice trick, as well as the use of the FOR statement with wildcard for your .msu files so you don't have to list seperate. Here is another way of doing the progress bar that I use. (Runs horizional bar in console).

    P.S. Also if you have a lot of updates like I do and don't want to hang around your computer and watch paint dry you can add
    a .wav file to notifiy you that it's done. If you want the code for that let me know and I will post it. Dos_Probie :D

    Code:
    @echo off&color e
    setlocal EnableDelayedExpansion
    :: PBar.Updates.cmd
    :: INSTALL
    for /f %%a in ('dir /b %systemdrive%\msu\*.msu') do (
    CLS
    echo Installing %%A
    %windir%\System32\wusa.exe %systemdrive%\msu\%%a /quiet /norestart
    )
    goto :progressbar
    :: EYECANDY
    :progressbar
    set Counter=0
    set Schalter=2
    set Width=0
    :1
    title [ + WINDOWS UPDATES INSTALLER + ]
    set /a Counter=%Counter% + 1
    set /a Display=%Counter% / 2
    FOR /L %%A IN (1,1,%Display%) DO (
       set Display=!Display!²
    )
    cls
    echo            Finalizing Windows Updates...                  %Counter%%%
    echo     ²!Display:~2,47!
    ping localhost -n 1 >nul
    if "%Counter%" == "100" goto :1-End
    goto :1
    :1-End
    echo.
    echo.
    echo.
    echo ALL UPDATES HAVE COMPLETED SUCCESSFULLY..WINDOWS WILL NOW REBOOT.
    :: DELAY
    ping 1.1.1.1 -n 1 -w 5000 >null
    :: REBOOT
    shutdown /r /t 1
    endlocal
    exit 
    
     
  5. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    Cerberus...

    PM me your email addy and I will send you the link to d/l my notify wave..
    (mdl would not allow me to post link here since I just joined and dont have nuff posts..go figure):worthy:
     
  6. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    Thanks for all the info on progressbar but I was looking for something real time.....no biggie. I created a vbs file to run .wav file at end of installation to let me know it is finished instead of watching it the whole time. lol Thanks again for all the input. Take care.
     
  7. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #7 Dos_Probie, Sep 15, 2012
    Last edited by a moderator: Apr 20, 2017
    Glad you got it worked out...:) you could also have done the wave from the batch without adding the .vbs

    Code:
    :: NOTIFY
    start/min sndrec32 /play /close %windir%\media\Peanuts.wav
    
    :: DELAY 
    ping -n 14 localhost 1>NUL 
     
  8. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    doin it that way will open player which I didnt want....using vbs just plays sound without opening player min to desktop. Like the vbs better personally.
     
  9. magsoud

    magsoud MDL Novice

    Dec 29, 2009
    19
    1
    0
    #9 magsoud, Nov 20, 2012
    Last edited by a moderator: Apr 20, 2017
    Please how to Add Percentage for
    Code:
    @ECHO OFF
    SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    PUSHD %~dp0
    FOR %%A IN (*-KB*.MSU) DO (
        CALL :SUB %%~nA
        ECHO= Installing KB!KB_NUM!
        >NUL TIMEOUT /t 3
        WUSA "%%~fA" /quiet /norestart)
    ECHO= == Press any key to restart ==
    >NUL PAUSE
    SHUTDOWN.EXE /r /t 0
    GOTO :EOF
    
    :SUB
    SET "KB_NUM=%*"
    FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"
    
     
  10. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    526
    371
    30
    Instead of a wav file, you can add this to the end of the cmd to have a beep.

    echo aY | choice /n
     
  11. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    You could stack beeps all on one line also ... echo aY | choice /n&echo aY | choice /n&echo aY | choice /n
     
  12. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #12 Dos_Probie, Jun 19, 2013
    Last edited by a moderator: Apr 20, 2017
    Or try some eye candy like this..
    Code:
    @echo off&color e
    setlocal EnableDelayedExpansion
    title [ MULTI-UPDATE INSTALLER ]
    :: Multi.UpdateInstaller.cmd
    :: AUTO INSTALLS .MSU UPDATES IN NUMERICAL ORDER 
    ::  MULTIPLE INSTALLER
    for /f %%a in ('dir/b %systemdrive%\Installs\updates\*.msu') do (
    echo == Installing Update ==    "%%a"
    echo.
    start /wait wusa %systemdrive%\Installs\updates\%%a /quiet /norestart
    )
    goto :progressbar
    :: EYECANDY
    :progressbar
    set Counter=0
    set Schalter=2
    set Width=0
    :1
    title [ + WINDOWS UPDATES INSTALLER + ]
    set /a Counter=%Counter% + 1
    set /a Display=%Counter% / 2
    FOR /L %%A IN (1,1,%Display%) DO (
       set Display=!Display!²
    )
    cls
    echo            Finalizing Windows Updates...                  %Counter%%%
    echo     ²!Display:~2,47!
    ping localhost -n 1 >nul
    if "%Counter%" == "100" goto :1-End
    goto :1
    :1-End
    echo.
    echo.
    echo.
    echo   ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
    echo   Ý                                            ÚÄÄÄ¿Þ
    echo   Ý     All Updates Installed Successfully     ³ û ³Þ
    echo   Ý                                            ÀÄÄÄÙÞ
    echo   ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
    echo.
    echo.
    echo.
    echo == Press any [KEY] to Close This Screen ==&pause>nul
    echo.
    exit
    
     
  13. AhrimanSefid

    AhrimanSefid MDL Junior Member

    Apr 12, 2010
    97
    0
    0
    Hi
    Thanks Very good But Me "for /f %%a in ('dir/b *.msu') do (" change not work.
    plz help me.
     
  14. AhrimanSefid

    AhrimanSefid MDL Junior Member

    Apr 12, 2010
    97
    0
    0
    Hi
    Thanks Very good But Me "for /f %%a in ('dir/b *.msu') do (" change not work.
    plz help me.
     
  15. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    Since you have taken no part in this Topic, AhrimanSefid, it is impossible for me to guess what you are having difficulty with.

    Please post your entire batch file and explain what exactly is happening when you run it!
     
  16. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #16 Dos_Probie, Sep 10, 2014
    Last edited by a moderator: Apr 20, 2017
    Try This..
    ~DP
    Code:
    @echo off&setlocal ENABLEDELAYEDEXPANSION&color 1f&&title, [ WUSA - 8.1 UPDATE INSTALLER ]
    pushD "%~dp0" & cd /d "%~dp0"
    :: ### SCAN FOR UPDATES--------------------------------------------------------
    for /F %%a in ('dir Updates\msu\*.msu ^|findstr /i "file(s)"') do set z=%%a
            echo Number Of Updates Found: %z%
    echo:&echo:
    :: ### INSTALLING UPDATES (reads updates in numerical order)-------------------
            echo == Installing %z% Windows Updates..(This may take a while, Please Wait)
    echo:
    for /R "%~dp0" %%A IN (*.MSU) DO (
            SET /A COUNT+=1
            ECHO= Installing !COUNT! of %z% = %%~nA
            >NUL TIMEOUT /t 3
            start /wait WUSA "%%A" /quiet /norestart
    )
    popD
    endlocal
    cls
    :: ### NOTIFICATION COMPLETE (plays selected .wav file when done)--------------
    set "wav=%windir%\media\Ring10.wav"
    echo All Updates Have Completed Successfully..
    start /min wmplayer.exe /play %wav%
    timeout /t 7 /nobreak>nul
    taskkill /f /im wmplayer.exe>nul
    exit
     
  17. TeamOS

    TeamOS MDL Guru

    May 27, 2013
    3,036
    1,739
    120
    its possible put progress like Dism If possible for my silent apps ?
     
  18. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    Did I understand that correctly?

    You want to install some applications in the background, (so that your end users are effectively unaware that you are installing them). Then you want to graphically show the progress of the 'silent' processes to the same end users, (so that they are fully aware that you are installing them).:kick: