Team OS : Your Only Destination To Custom OS !!

Welcome to TeamOS Community, Register or Login to the Community to Download Torrents, Get Access to Shoutbox, Post Replies, Use Search Engine and many more features. Register Today!

Tutorials Create a log with the date, time and version of a downloaded file [BAT-wmic]

juanamm

Uploader
Uploader
Power User
✅ Verified Member
Member
Downloaded
5.7 GB
Uploaded
448.6 GB
Ratio
78.11
Seedbonus
134,973
Upload Count
217 (223)
Member for 5 years
Create a log with the date, time and version of a downloaded file [BAT-wmic]

A few days ago I shared with you a on how to download a file and then run it silently.

Today we will continue working with that script and I will share with you how to create a log where date and time of the download, file version and date and time of creation of the downloaded file will be stored.

I will use a batch file and wmic for internal processes.

I have commented on the lines to make the script easier to understand. ::is a comment

I have created extra date and time variables in case you want to use them and also at the end you can modify the form of the presentation of the date and time according to the uses of your countries: datestamp, timestamp & fullstamp
In some countries MONTH/DAY/YEAR is used in others DAY/MONTH/YEAR etc.

They can change the location of the variables (%D, %M, %Y) to achieve the desired result.


Every time we run this script, a new line will be created in the log.txt file.
If the file is not created, the script will create it and start typing on line 1 of the file.

In this example the log file will be saved in the same download folder, you can change the path if you wish.

>> "%downloadFolder%"\log.txt


They can modify or remove whatever they want, knowing what they are doing. ;)

Bash:
@ECHO OFF
::set download folder
set "downloadFolder=%userprofile%\Downloads\avast_updates"
::set download file url
set downloadUrl=https://install.avcdn.net/vps18/vpsupd.exe

::set local date time format
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%MM%%DD%%YYYY%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
::set character TAB
set TAB=    "
set "TAB=%TAB:"=%

::downloading file ...
bitsadmin /transfer myAvastUpdates /download /priority normal ^
"%downloadUrl%" "%downloadFolder%\vpsupd.exe"


setlocal enableextensions
    ::set file to compare versions  
    set "file=%downloadFolder%\vpsupd.exe"
    if not defined file goto :eof
    if not exist "%file%" goto :eof

    set "vers="
    ::get version file
    FOR /F "tokens=2 delims==" %%a in ('
        wmic datafile where name^="%file:\=\\%" get Version /value
    ') do set "vers=%%a"
    ::get file creation date
    FOR /F "tokens=2 delims==" %%a in ('
        wmic datafile where name^="%file:\=\\%" get CreationDate /value
    ') do set "Line=%%a"
    ::set creation date & time format
    set Y=%Line:~0,4%
    set M=%Line:~4,2%
    set D=%Line:~6,2%
    set H=%Line:~8,2%
    set min=%Line:~10,2%
    ::set creation date format
    set "creation_Date=%D%/%M%/%Y%"
    ::set creation time format
    set "creation_Time=%H%:%min%"
    ::save result "download date and time / file version / file creation date / creation time" in the log.txt file
  echo %DD%-%MM%-%YYYY% %HH%:%Min%%TAB%%TAB%%vers%%TAB%%TAB%%creation_Date% %creation_Time% >> "%downloadFolder%"\log.txt
endlocal
::silent run of downloaded file
"%downloadFolder%\vpsupd.exe" /silent
exit

RESULT:
DOWNLOAD DATE FILE VERSION FILE MODIFIED DATE 04-08-2020 01:24 11.1.2241.1482 03/08/2020 13:24

You can create the log.txt file with the headings properly tabbed for this script.
If you don't know how to do it, I'll share .BAT and log file with the titles tabulated correctly.


 

*Maestro*

Power User
Member
Downloaded
368.9 GB
Uploaded
81.8 TB
Ratio
226.97
Seedbonus
711,487
Upload Count
0 (0)
Member for 9 years
Nice. Thank you for some excellent information.
sweet.
 

leperdu

✅ Verified Member
Member
Downloaded
209.5 GB
Uploaded
14.9 TB
Ratio
72.94
Seedbonus
335,924
Upload Count
0 (0)
Member for 7 years
Thank you.

May be very helpful in some cases.
 
Top