Skip to content

Instantly share code, notes, and snippets.

@curability4apish
Last active June 3, 2025 11:45
Show Gist options
  • Save curability4apish/96c2f1bb45426afac7cf2761ff73b9f7 to your computer and use it in GitHub Desktop.
Save curability4apish/96c2f1bb45426afac7cf2761ff73b9f7 to your computer and use it in GitHub Desktop.
@echo off
setlocal enabledelayedexpansion
rem Manually define the Downloads folder path here
set "downloadsFolder=D:\Downloads"
rem Check if the path is valid
if not exist "!downloadsFolder!" (
echo Error: The specified folder does not exist.
goto :end
)
:main
cls
echo Listing all .exe and .zip files in the specified Downloads folder (newest to oldest):
set "count=0"
for /f "tokens=*" %%F in ('dir "!downloadsFolder!\*.exe" "!downloadsFolder!\*.zip" /b /a-d /o-d /t:c 2^>nul') do (
set /a count+=1
echo !count!. %%F
set "file[!count!]=%%F"
)
rem Check if any .exe or .zip files were found
if %count%==0 (
echo No .exe or .zip files found in the Downloads folder.
goto :list_other_files
)
rem Prompt user to select a file
echo.
echo Press 0 to list other files (e.g., .docx, .mp4) in the Downloads folder.
set /p "choice=Enter the number of the file you want to select: "
if %choice%==0 (
goto :list_other_files
)
set "selectedFile=!file[%choice%]!"
rem Validate the user's choice
if "!selectedFile!"=="" (
echo Invalid selection.
goto :main
)
goto :process_file
:list_other_files
cls
echo Listing other files in the specified Downloads folder (newest to oldest):
set "count=0"
for /f "tokens=*" %%F in ('dir "!downloadsFolder!\*" /b /a-d /o-d /t:c 2^>nul ^| findstr /v /i /e ".exe .zip"') do (
set /a count+=1
echo !count!. %%F
set "file[!count!]=%%F"
)
rem Check if any other files were found
if %count%==0 (
echo No other files found in the Downloads folder.
goto :main
)
rem Prompt user to select a file from the additional list
echo.
echo Press 0 to go back to the previous menu.
set /p "choice=Enter the number of the file you want to select: "
if %choice%==0 (
goto :main
)
set "selectedFile=!file[%choice%]!"
rem Validate the user's choice
if "!selectedFile!"=="" (
echo Invalid selection.
goto :list_other_files
)
goto :process_file
:process_file
set "filePath=!downloadsFolder!\!selectedFile!"
echo Selected File Path: !filePath!
rem Check if the file exists
if not exist "!filePath!" (
echo Error: The selected file does not exist.
goto :main
)
rem Calculate the MD5 hash and output to temp.txt
certUtil -hashfile "!filePath!" MD5 > temp.txt
rem Read the output and find the line that contains the actual hash
set "hash="
for /f "skip=1 tokens=*" %%A in (temp.txt) do (
if not defined hash (
set "hash=%%A"
)
)
rem Remove trailing spaces from the hash
for %%A in (!hash!) do set "hash=%%A"
rem Check if hash is set
if not defined hash (
echo Error: Could not calculate the hash.
goto :main
)
echo Hash: !hash!
rem Open the URL in the default web browser
start https://www.virustotal.com/gui/file/!hash!
del temp.txt
goto :main
:end
pause
@curability4apish
Copy link
Author

curability4apish commented Jan 19, 2025

VirusTotal Opener

Description

This batch script opens VirusTotal's webpage of the scan result of the file you want to scan. If it hasn't been uploaded, you may upload it manually through your browser.

How It Works

  1. The script initially lists all .exe and .zip files in the user's Downloads folder.

  2. The user is prompted to select a file from the list by entering the corresponding number.

  3. If the user enters 0, the script lists other types of files in the Downloads folder.

  4. The user can then select a file from the new list or go back to the previous menu by entering 0.

  5. Once a file is selected, the script calculates its MD5 hash.

  6. The script opens a VirusTotal URL with the calculated hash for scanning.

  7. The script loops back to the main menu after processing the file.

Prerequisites

  • WindowsOS
  • The certUtil utility (included with Windows) to calculate the MD5 hash.
  • Internet connection to access VirusTotal.

v2 Updates

  • Solve the bug that if one enters a invalid number the program would break the loop.
  • Add the feature that if one enters -1, move all listed files to folder %userprofile%/Desktop/Trash.

@curability4apish
Copy link
Author

curability4apish commented Jan 19, 2025

A simplified version.

@echo off
setlocal enabledelayedexpansion

rem Check if any arguments are provided
if "%~1"=="" (
    echo Please provide at least one file as an argument.
    pause
    goto :end
)

rem Loop through each file provided as an argument
for %%F in (%*) do (
    echo File: %%F
    rem Calculate the SHA256 hash and output to temp.txt
    certUtil -hashfile "%%F" sha256 > temp.txt
    
    rem Read the output and find the line that contains the actual hash
    set hash=
    for /f "skip=1" %%A in (temp.txt) do (
        set hash=%%A
        goto :break
    )
    :break
    echo Hash: !hash!
    rem Open the VirusTotal URL in the default web browser
    start "" "https://www.virustotal.com/gui/file/!hash!"
    del temp.txt
)

:end
endlocal
pause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment