This is a part of my code :
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
| 1. I need a code to overwrite the progress bar line; that supports Windows Vista to the Current version.
I searched about this topic and I found awesome codes about this problem. But I couldn't find what I wanted..
viewtopic.php?t=7898
The "Move cursor to *any position* using just ECHO command" didn't work at Windows 10;(Without editing registry)
viewtopic.php?p=43716#p43716
The "timeout 1 > con" worked in every Windows version, but I didn't find the way how to find "where is the line current is"
So It was possible to overwrite another line like this image.
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
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 there is no way to use multiple hybrid .net batch..
https://superuser.com/a/1166728
And <nul set /p " didn't work at Windows 10.
Is there another way to update progress bar that works on Windows vista to 10?
| 2. What is the difference between bitsadmin and bitsadmin.exe?
Code: Select all
:: Save this code to .bat/.cmd to see this bug.
bitsadmin.exe /cancel wget_download > nul
pause > nul
bitsadmin /cancel wget_download > nul
pause > nul
Here is a screenshot of output.
| 3. What does 'call' does?
Code: Select all
CALL BITSADMIN.EXE /ADDFILE Wget_download "%WGET_URL%" "%WGET_PATH%\wget.exe" > NUL
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%%_"