Is there a way to update progress bar in Windows Vista to 10?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
WiVi71
Posts: 1
Joined: 06 Jan 2020 02:33

Is there a way to update progress bar in Windows Vista to 10?

#1 Post by WiVi71 » 07 Jan 2020 10:15

I am making a simple code to download Wget with BITSADMIN contains progress bar.

Code: Select all

@ECHO OFF
:: This is a part of my batch
SET "WGET_URL=https://eternallybored.org/misc/wget/1.20.3/64/wget.exe"
SET "WGET_PATH=%USERPROFILE%"

:Prepare
REM * Prepare - Set Window
COLOR 07
TITLE GMK: Downloading Wget
MODE CON COLS=84 LINES=25

REM * Prepare - Logo
ECHO                            / \                   / \       / \
ECHO           / \ /\       /     \    / \       /     ^>/ \/    // \
ECHO         /    /  /  / \/    / \/  /     ^>    /     //    /\ //    // \
ECHO       /    /  /  /   //   /   // /     /    /     //    /    /    //   //\
ECHO       \ /  /  /   //   /   // /     //\ /     //    // \/    //   //    ^>
ECHO        /  /  /   //   /   // /     //  / ^<    //    //    /\ //   //     / /\
ECHO       \/  /   //   /   // / / \//  /  / \/  \ //    /  /   \//     / /  /
ECHO            \ /\ /   //  ^</   //  /  /  ^|\\   /    /  /  / \/     / /  /
ECHO                 /\ //   / \//\/   \  ^|/  /   \ /\/    \^</    /  \/
ECHO                 \ /     \ /          \  /                   \ /
ECHO                                          ˇ           
ECHO                                   --  Some Text --
ECHO:
ECHO -----------------------------------------------------------------------------------
ECHO:

REM * Download - Wget: Prepare Download
:: Need to use call in addfile(why?)
BITSADMIN.EXE /CANCEL Wget_download > NUL
BITSADMIN.EXE /CREATE /DOWNLOAD Wget_download > NUL
CALL BITSADMIN.EXE /ADDFILE Wget_download "%WGET_URL%" "%WGET_PATH%\wget.exe" > NUL
BITSADMIN.EXE /SETPRIORITY Wget_download HIGH > NUL
BITSADMIN.EXE /SETPROXYSETTINGS Wget_download AUTODETECT > NUL

REM * Download - Wget: Get Basic Information
:: Proxy option has never tested
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETCREATIONTIME Wget_download') DO SET "BITS_CREATIONTIME=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETDISPLAYNAME Wget_download') DO SET "BITS_JOBNAME=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETPRIORITY Wget_download') DO SET "BITS_PRIORITY=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETPROXYUSAGE Wget_download') DO SET "BITS_PROXYUSAGE=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETPROXYLIST Wget_download') DO SET "BITS_PROXYLIST=%%A"

REM * Download - Wget: Show Basic Information
ECHO This download process is using BITSADMIN ^(BITS administration utility^)
ECHO:
ECHO %BITS_CREATIONTIME% - Started Job : %BITS_JOBNAME% [Priority : %BITS_PRIORITY%]
ECHO Current proxy usage setting is "%BITS_PROXYUSAGE%" [Proxy List : %BITS_PROXYLIST%]
ECHO:
ECHO Downloading %WGET_URL%

REM * Download - Wget: Start Download
BITSADMIN.EXE /RESUME Wget_download > NUL

:BITSADMIN_State_Loop
REM * Download - Wget: Update State
:: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/bitsadmin-getstate
:: There is an overflowing problem(18446744073709551615 problem)
:: Need to loop fast
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETSTATE Wget_download') DO (
	ECHO Awaiting TRANSFERRING State..  [ Current State : %%A ]
	REM :: IF "%%A" == "ERROR" GOTO BITSADMIN_Download_Error
	REM :: IF "%%A" == "TRANSIENT_ERROR" GOTO BITSADMIN_Download_Error
	REM :: IF "%%A" == "SUSPENDED" GOTO BITSADMIN_State_Else
	REM :: IF "%%A" == "CANCELED" GOTO BITSADMIN_State_Else
	IF "%%A" == "TRANSFERRING" ECHO: & GOTO BITSADMIN_Download_Loop
	IF "%%A" == "ACKNOWLEDGED" GOTO BITSADMIN_Download_Success
	IF "%%A" == "TRANSFERRED" GOTO BITSADMIN_Download_Succes
)

TIMEOUT 1 > NUL
GOTO BITSADMIN_State_Loop

:BITSADMIN_Download_Loop
:: Need to loop fast
REM * Download - Wget: Update Bytes
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETBYTESTOTAL Wget_download') DO SET "BITS_TOTALBYTES=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETBYTESTRANSFERRED Wget_download') DO SET "BITS_TRANSFERREDBYTES=%%A"

REM * Download - Wget: Get percent
SET /A "BITS_PERCENT=(BITS_TRANSFERREDBYTES*100)/BITS_TOTALBYTES"

REM * Download - Wget: Convert bytes to Kibibytes
SET /A "BITS_TOTALKIB=BITS_TOTALBYTES/1024"
SET /A "BITS_TRANSFERREDKIB=BITS_TRANSFERREDBYTES/1024"

REM * Download - Wget: Get Progress bar
:: CALL SET is slow than SET
:: Do not use variable starts with "A"
SET "BITS_HASHS="
SET "BITS_UNDERLINES="
SET /A "BITS_HASHNUM=BITS_PERCENT/3"
FOR /L %%A IN (1,1,%BITS_HASHNUM%) DO CALL SET "BITS_HASHS=%%BITS_HASHS%%#"
SET /A "BITS_UNDERLINENUM=33-BITS_HASHNUM"
FOR /L %%A IN (1,1,%BITS_UNDERLINENUM%) DO CALL SET "BITS_UNDERLINES=%%BITS_UNDERLINES%%_"

REM * Download - Wget: Update Progress bar
:: Need to add state checking
ECHO wget.exe       [%BITS_HASHS%%BITS_UNDERLINES%]  %BITS_PERCENT%%% ^| %BITS_TRANSFERREDKIB%KiB/%BITS_TOTALKIB%KiB
IF "%BITS_PERCENT%" == "100" GOTO BITSADMIN_Download_Success
TIMEOUT 1 > NUL
GOTO BITSADMIN_Download_Loop

:BITSADMIN_Download_Success
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETCOMPLETIONTIME Wget_download') DO SET "BITS_COMPLETIONTIME=%%A"
BITSADMIN.EXE /COMPLETE Wget_download > NUL
IF %ERRORLEVEL% NEQ 0 REM :: GOTO BITSADMIN_Download_Error
ECHO:
ECHO %BITS_CREATIONTIME% - Job %BITS_JOBNAME% Completed
ECHO Saved file to "%WGET_PATH%\wget.exe"
EXPLORER.EXE %WGET_PATH%
pause
img.png
img.png (18.4 KiB) Viewed 266 times
And I have some questions about this batch.

| 1. I need a code to refresh the progress bar; Supports Windows Vista to Current version.

I searched about it and I found awesome codes about this problem. But I didn't find what I want.

viewtopic.php?t=7898
The "Move cursor to *any position* using just ECHO command" doesn't work at Windows 10;(Without editing registry)

viewtopic.php?p=43716#p43716
The "timout 1 > con" worked in every Windows version, but I can't find the way how to find "where is the line current is"
This can make a problem like this :
123.png
123.png (2.37 KiB) Viewed 255 times
https://stackoverflow.com/a/44138141

Code: Select all

@echo off
setlocal EnableDelayedExpansion
MODE CON COLS=84 LINES=25
rem Get a BS and TAB control characters
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
REM Be sure that TAB variable contains an Ascii 9 character
::https://www.dostips.com/forum/viewtopic.php?t=7898
for /F "skip=4 delims=pR tokens=2" %%a in ('reg query hkcu\environment /v temp' ) do set "TAB=%%a"
rem Then, the method for newer versions
rem http://www.dostips.com/forum/viewtopic.php?f=3&t=1733&p=6840#p6853
for /F "tokens=2 delims=0" %%a in ('shutdown /? ^| findstr /BC:E') do if not defined TAB set "TAB=%%a"

rem Leave some empty lines and do a PAUSE
echo Three empty lines below + pause
echo/
echo/
echo/
pause

rem Get width of screen buffer, set number of lines to go above
set /A buffWid=84, linesAbove=3

rem Assemble the "go above" control string with the proper number of BSs
set "BSs="
set /A "cntBS = 2 + (buffWid + 7) / 8 * linesAbove"
for /L %%i in (1,1,%cntBS%) do set "BSs=!BSs!!BS!"

rem Move cursor up the desired number of lines
echo %TAB%!BSs!

echo Hello,
echo World
echo This line overwrites the one with PAUSE output
pause
This one doesn't works at Windows 10

viewtopic.php?p=54400#p54400
viewtopic.php?p=54392#p54392
I don't want to use external tools.(like cscript/wscript/powershell; some computers block these.)
hybrid batch is ok(only for .net) but hybrid batch is already using to choose files(with js.net) but I can't find a way to use multiple hybrid batch to .net..

https://superuser.com/a/1166728
And <nul set /p " didn't work at Windows 10.

Is there another way to update progress bar works to Windows vista to 10?

| 2. What is the difference between bitsadmin and bitsadmin.exe?

Code: Select all

:: You need to save this code to .bat/cmd to see the bug.
bitsadmin.exe /cancel wget_download > nul
pause
bitsadmin /cancel wget_download > nul
pause
The First command works but second does not.
Here is a screenshot.
1547.jpg
1547.jpg (107.92 KiB) Viewed 255 times
The second one means "Maximum setlocal recursion level reached." in english.

| 3. What does 'call' does?

Code: Select all

CALL BITSADMIN.EXE /ADDFILE Wget_download "%WGET_URL%" "%WGET_PATH%\wget.exe" > NUL
In Here the batch use "call bitsadmin"
What does "call" does to bitsadmin at that batch?

Code: Select all

FOR /L %%A IN (1,1,%BITS_HASHNUM%) DO CALL SET "BITS_HASHS=%%BITS_HASHS%%#"
SET /A "BITS_UNDERLINENUM=33-BITS_HASHNUM"
FOR /L %%A IN (1,1,%BITS_UNDERLINENUM%) DO CALL SET "BITS_UNDERLINES=%%BITS_UNDERLINES%%_"
And why do I need to use "call set" to set multiple blanks?(e.g.#######)
Isn't "call set" slow?
If "call set" is slow, Is there another way to set multiple blocks?

jfl
Posts: 115
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Is there a way to update progress bar in Windows Vista to 10?

#2 Post by jfl » 10 Jan 2020 09:26

2. What is the difference between bitsadmin and bitsadmin.exe?
If you don't provide the extension, cmd.exe will try all the extensions in enviroment variable PATHEXT, and use the first program that matches.
Could it be that you named your test script "bitsadmin.bat" ?
In that case, this explains why you have an infinite loop: Contrary to other types of programs, invoking batch files likes this JUMPS into the other batch, and never comes back.
What does 'call' does?
Its primary role is to call an external batch file (overcoming the issue I mentioned above), or call an internal subroutine.
There's also a side role, which is to parse an instruction twice. It's only needed in loops, when a VARIABLE changes within the loop. All %VARIABLE% references are expanded before the loop starts, so you don't see the changes. To get the updated value, you need to use !VARIABLE! expansion, or use the 'call ... %%VARIABLE%% ...' syntax. (Notice the double % signs: The initial % expansion before the loops starts changes each %% to a %, then the second parsing done by call expands the remaining %VARIABLE% to its updated value.)

pieh-ejdsch
Posts: 212
Joined: 04 Mar 2014 11:14
Location: germany

Re: Is there a way to update progress bar in Windows Vista to 10?

#3 Post by pieh-ejdsch » 17 Jan 2020 17:49

You can change the prompt so that the display can be used as output.

viewtopic.php?f=3&t=8051

Code: Select all

@ECHO OFF

if :%1 == :print shift &goto :print
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

:: This is a part of my batch
SET "WGET_URL=https://eternallybored.org/misc/wget/1.20.3/64/wget.exe"
SET "WGET_PATH=%USERPROFILE%"
:Prepare
REM * Prepare - Set Window
COLOR 07
TITLE GMK: Downloading Wget
:MODE CON COLS=84 LINES=25

REM * Prepare - Logo
ECHO                            / \                   / \       / \
ECHO           / \ /\       /     \    / \       /     ^>/ \/    // \
ECHO         /    /  /  / \/    / \/  /     ^>    /     //    /\ //    // \
ECHO       /    /  /  /   //   /   // /     /    /     //    /    /    //   //\
ECHO       \ /  /  /   //   /   // /     //\ /     //    // \/    //   //    ^>
ECHO        /  /  /   //   /   // /     //  / ^<    //    //    /\ //   //     / /\
ECHO       \/  /   //   /   // / / \//  /  / \/  \ //    /  /   \//     / /  /
ECHO            \ /\ /   //  ^</   //  /  /  ^|\\   /    /  /  / \/     / /  /
ECHO                 /\ //   / \//\/   \  ^|/  /   \ /\/    \^</    /  \/
ECHO                 \ /     \ /          \  /                   \ /
ECHO                                          ?           
ECHO                                   --  Some Text --
ECHO:
ECHO -----------------------------------------------------------------------------------
ECHO:

REM * Download - Wget: Prepare Download
:: Need to use call in addfile(why?)
BITSADMIN.EXE /CANCEL Wget_download > NUL
BITSADMIN.EXE /CREATE /DOWNLOAD Wget_download > NUL
CALL BITSADMIN.EXE /ADDFILE Wget_download "%WGET_URL%" "%WGET_PATH%\wget.exe" > NUL
BITSADMIN.EXE /SETPRIORITY Wget_download HIGH > NUL
BITSADMIN.EXE /SETPROXYSETTINGS Wget_download AUTODETECT > NUL

REM * Download - Wget: Get Basic Information
:: Proxy option has never tested
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETCREATIONTIME Wget_download') DO SET "BITS_CREATIONTIME=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETDISPLAYNAME Wget_download') DO SET "BITS_JOBNAME=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETPRIORITY Wget_download') DO SET "BITS_PRIORITY=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETPROXYUSAGE Wget_download') DO SET "BITS_PROXYUSAGE=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETPROXYLIST Wget_download') DO SET "BITS_PROXYLIST=%%A"

REM * Download - Wget: Show Basic Information
ECHO This download process is using BITSADMIN ^(BITS administration utility^)
ECHO:
ECHO %BITS_CREATIONTIME% - Started Job : %BITS_JOBNAME% [Priority : %BITS_PRIORITY%]
ECHO Current proxy usage setting is "%BITS_PROXYUSAGE%" [Proxy List : %BITS_PROXYLIST%]
ECHO:
ECHO Downloading %WGET_URL%

REM * Download - Wget: Start Download
BITSADMIN.EXE /RESUME Wget_download > NUL

:BITSADMIN_State_Loop
REM * Download - Wget: Update State
:: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/bitsadmin-getstate
:: There is an overflowing problem(18446744073709551615 problem)
:: Need to loop fast
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETSTATE Wget_download') DO (
	cmd /c if . equ . "%~f0" print "!CR!  Awaiting TRANSFERRING State..  [ Current State : %%A ]"
	REM :: IF "%%A" == "ERROR" GOTO BITSADMIN_Download_Error
	 rem GOTO BITSADMIN_Download_%%A
	REM :: IF "%%A" == "TRANSIENT_ERROR" GOTO BITSADMIN_Download_Error
	REM :: IF "%%A" == "SUSPENDED" GOTO BITSADMIN_State_Else
	REM :: IF "%%A" == "CANCELED" GOTO BITSADMIN_State_Else
	IF "%%A" == "TRANSFERRING" ECHO: & GOTO BITSADMIN_Download_Loop
	IF "%%A" == "ACKNOWLEDGED" GOTO BITSADMIN_Download_Success
	IF "%%A" == "TRANSFERRED" GOTO BITSADMIN_Download_Succes
)

:TIMEOUT 1 > NUL
GOTO BITSADMIN_State_Loop

:BITSADMIN_Download_TRANSFERRING
:BITSADMIN_Download_Loop
:: Need to loop fast
REM * Download - Wget: Update Bytes
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETBYTESTOTAL Wget_download') DO SET "BITS_TOTALBYTES=%%A"
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETBYTESTRANSFERRED Wget_download') DO SET "BITS_TRANSFERREDBYTES=%%A"

REM * Download - Wget: Get percent
SET /A "BITS_PERCENT=(BITS_TRANSFERREDBYTES*100)/BITS_TOTALBYTES"

REM * Download - Wget: Convert bytes to Kibibytes
SET /A "BITS_TOTALKIB=BITS_TOTALBYTES/1024"
SET /A "BITS_TRANSFERREDKIB=BITS_TRANSFERREDBYTES/1024"

REM * Download - Wget: Get Progress bar
:: CALL SET is slow than SET
:: Do not use variable starts with "A"
SET "BITS_HASHS="
SET "BITS_UNDERLINES="
SET /A "BITS_HASHNUM=BITS_PERCENT/3"
FOR /L %%A IN (1,1,%BITS_HASHNUM%) DO CALL SET "BITS_HASHS=%%BITS_HASHS%%#"
SET /A "BITS_UNDERLINENUM=33-BITS_HASHNUM"
FOR /L %%A IN (1,1,%BITS_UNDERLINENUM%) DO CALL SET "BITS_UNDERLINES=%%BITS_UNDERLINES%%_"

REM * Download - Wget: Update Progress bar
:: Need to add state checking
cmd /c if . equ . "%~f0" print " !CR!  wget.exe       [%BITS_HASHS%%BITS_UNDERLINES%]  %BITS_PERCENT%%% ^| %BITS_TRANSFERREDKIB%KiB/%BITS_TOTALKIB%KiB"

 rem ECHO 
IF "%BITS_PERCENT%" == "100" GOTO BITSADMIN_Download_Success
TIMEOUT 1 > NUL
GOTO BITSADMIN_Download_Loop

:BITSADMIN_Download_Success
:BITSADMIN_Download_ACKNOWLEDGED
:BITSADMIN_Download_TRANSFERRED
FOR /F "TOKENS=*" %%A IN ('BITSADMIN.EXE /RAWRETURN /GETCOMPLETIONTIME Wget_download') DO SET "BITS_COMPLETIONTIME=%%A"
BITSADMIN.EXE /COMPLETE Wget_download > NUL
IF %ERRORLEVEL% NEQ 0 REM :: GOTO BITSADMIN_Download_Error
ECHO:
ECHO %BITS_CREATIONTIME% - Job %BITS_JOBNAME% Completed
ECHO Saved file to "%WGET_PATH%\wget.exe"
EXPLORER.EXE %WGET_PATH%
pause
exit /b

:BITSADMIN_Download_Error
:BITSADMIN_Download_TRANSIENT_ERROR
echo BITSADMIN_Download_Error

exit /b 1

:print
 rem Please note that this function/batch can NOT be started with a call.
 rem  Since it terminates the calling batch.
 rem  Usage: cmd /c if. equ . "Path\batchname" "whiteSpaces ...message Text"
@echo on
@( setlocal enabledelayedexpansion
set "prompt=%~1"
)
%== !required this is an empty Line, do not remove! ==%
@( echo off
Phil

Post Reply