Friday 7 April 2023

Lifesaving useful .bat or batch files

  1. Matrix.bat - This file will create a Matrix-like effect on your screen. To use it, open Notepad and paste the following code:
  2. arduino
    @echo off color 0a :start echo %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% goto start

    Save the file as "Matrix.bat" and run it. The script will create a continuous stream of random numbers on your screen, giving it a Matrix-like appearance. To stop the script, press Ctrl + C.

  3. Shutdown Timer.bat - This file will allow you to set a timer for your computer to shut down. To use it, open Notepad and paste the following code:
bash
@echo off color 0a title Shutdown Timer echo Welcome to Shutdown Timer! echo. set /p time=How many minutes to shut down: echo. echo Your computer will shut down in %time% minute(s). shutdown -s -t %time% -c "Your computer will now shut down."

Save the file as "Shutdown Timer.bat" and run it. You will be prompted to enter the number of minutes you want the computer to shut down after.

3. Password Generator.bat - This file will generate a random password for you. To use it, open Notepad and paste the following code:

bash
@echo off setlocal enabledelayedexpansion set "chars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+={}[]|:;'<>,.?/" set "length=12" set "password=" for /l %%a in (1,1,%length%) do ( set /a rand=!random! %% 94 set "password=!password!!chars:~!rand!,1!" ) echo Your random password is: %password% pause>nul

Save the file as "Password Generator.bat" and run it. The script will generate a random password for you.

4. System Information.bat - This file will display detailed system information about your computer. To use it, open Notepad and paste the following code:

bash
@echo off systeminfo pause

Save the file as "System Information.bat" and run it. The script will display system information including the operating system, processor, installed memory, and more.

5. Automated backup: This batch file can be used to automate the process of backing up important files. Here's the code:

bash

@echo off

set source=c:\important\files

set destination=d:\backup

xcopy /s /e /y %source% %destination%

  1. Drive Space Checker.bat - This file will display the amount of free space on a specified drive. To use it, open Notepad and paste the following code:
bash
@echo off set /p drive=Enter drive letter: echo. echo Free space on %drive%: fsutil volume diskfree %drive%: pause

Save the file as "Drive Space Checker.bat" and run it. The script will prompt you to enter a drive letter. It will then display the amount of free space on the specified drive.

7. Batch File Alarm Clock.bat - This file will act as an alarm clock and play a sound at a specified time. To use it, open Notepad and paste the following code:

sql
@echo off set /p hour=Enter hour (24-hour format): set /p minute=Enter minute: set /p sound=Enter sound file name: echo. echo Alarm set for %hour%:%minute% :loop if %time:~0,2%==%hour% if %time:~3,2%==%minute% ( echo Playing sound... start "" "%sound%" goto end ) goto loop :end

Save the file as "Batch File Alarm Clock.bat" and run it. The script will prompt you to enter an hour (in 24-hour format), a minute, and the name of a sound file. It will then wait until the specified time and play the sound.

8. Batch File Calculator.bat - This file will act as a simple calculator and perform basic arithmetic operations. To use it, open Notepad and paste the following code:

bash
@echo off set /p num1=Enter first number: set /p op=Enter operator (+, -, *, /): set /p num2=Enter second number: if "%op%"=="+" set /a result=%num1%+%num2% if "%op%"=="-" set /a result=%num1%-%num2% if "%op%"=="*" set /a result=%num1%*%num2% if "%op%"=="/" set /a result=%num1%/%num2% echo. echo Result: %result% pause

Save the file as "Batch File Calculator.bat" and run it. The script will prompt you to enter two numbers and an operator (+, -, *, /). It will then perform the specified arithmetic operation and display the result.

9. Batch File Text to Speech Converter.bat - This file will convert a specified text to speech. To use it, open Notepad and paste the following code:

vbnet
@echo off set /p text=Enter text to convert to speech: echo. echo Converting text to speech... echo CreateObject("SAPI.SpVoice").Speak "%text%" > speak.vbs start speak.vbs pause

Save the file as "Batch File Text to Speech Converter.bat" and run it. The script will prompt you to enter text. It will then create a VBS script that will convert the text to speech using the Microsoft Speech API and play the speech.

10. Batch File Stopwatch.bat - This file will act as a stopwatch and display the elapsed time. To use it, open Notepad and paste the following code:

bash
@echo off set /a sec=0 set /a min=0 set /a hr=0 :start cls echo Stopwatch echo %hr%:%min%:%sec% set /a sec+=1 if %sec%==60 ( set /a sec=0 set /a min+=1 ) if %min%==60 ( set /a min=0 set /a hr+=1 ) timeout /t 1 /nobreak > nul goto start

Save the file as "Batch File Stopwatch.bat" and run it. The script will act as a stopwatch and display the elapsed time in hours, minutes, and seconds.

11. Batch File IP Address Checker.bat - This file will display the IP address of the computer running the script. To use it, open Notepad and paste the following code:

bash
@echo off for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr /i "IPv4 Address"') do set ip=%%i echo Your IP Address is: %ip:~1% pause

Save the file as "Batch File IP Address Checker.bat" and run it. The script will display the IP address of the computer running the script.

12. Batch File Clipboard Manager.bat - This file will save your clipboard history to a text file for easy access later. To use it, open Notepad and paste the following code:

bash
@echo off setlocal set maxlines=10 set file=%TEMP%\clipboard.txt if not exist "%file%" type nul > "%file%" for /f "usebackq delims=" %%a in (`clip`) do ( findstr /v /c:"%%a" "%file%" > nul && ( echo %%a>>"%file%" more +%maxlines% "%file%" > nul ) ) endlocal

Save the file as "Batch File Clipboard Manager.bat" and run it. The script will save your clipboard history to a text file located at %TEMP%\clipboard.txt. By default, it will save up to 10 lines of clipboard history. You can change the value of the "maxlines" variable to increase or decrease the number of lines saved.

13. Batch File Disk Cleanup.bat - This file will perform a disk cleanup of your computer, freeing up space by deleting unnecessary files. To use it, open Notepad and paste the following code:

bash
@echo off echo Cleaning up disk... cleanmgr /sagerun:1 > nul echo. echo Disk cleanup complete! pause

Save the file as "Batch File Disk Cleanup.bat" and run it. The script will run the built-in Windows Disk Cleanup utility with the "sagerun:1" flag, which specifies the settings to use for the cleanup. You can customize these settings by running the Disk Cleanup utility manually and saving your settings as "sagerun:1".

14. Batch File System Information.bat - This file will display information about your computer's system configuration, including the CPU, memory, and disk space. To use it, open Notepad and paste the following code:

css
@echo off systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type" /C:"Total Physical Memory" /C:"Available Physical Memory" /C:"Virtual Memory: Max Size" /C:"Virtual Memory: Available" /C:"Virtual Memory: In Use" /C:"Page File Location(s)" /C:"Host Name" /C:"Processor(s)" /C:"BIOS Version" /C:"Domain" /C:"Logon Server" /C:"Hotfix(s)" /C:"Network Card(s)" /C:"Disk(s)" > "%TEMP%\sysinfo.txt" start notepad "%TEMP%\sysinfo.txt"

Save the file as "Batch File System Information.bat" and run it. The script will use the built-in Windows System Information utility to gather information about your system configuration and save it to a text file located at %TEMP%\sysinfo.txt. It will then open the text file in Notepad for easy viewing.

15. Batch File WiFi Password Revealer.bat - This file will reveal the saved WiFi passwords on your Windows computer. To use it, open Notepad and paste the following code:

bash
@echo off echo Revealing saved WiFi passwords... echo. netsh wlan show profile > "%TEMP%\profiles.txt" for /f "tokens=2 delims=:" %%a in ('type "%TEMP%\profiles.txt" ^| findstr /c:"All User Profile"') do ( echo WiFi Profile: %%a netsh wlan show profile "%%a" key=clear | findstr /c:"Key Content" echo. ) echo Done! pause

Save the file as "Batch File WiFi Password Revealer.bat" and run it. The script will use the built-in Windows netsh command to show a list of saved WiFi profiles and their passwords. It will save the list to a text file located at %TEMP%\profiles.txt, then loop through the list and reveal the passwords for each profile.

16. Batch File IP Config Viewer.bat - This file will display information about your computer's IP configuration, including the IP address, subnet mask, default gateway, and DNS servers. To use it, open Notepad and paste the following code:

sql
@echo off ipconfig /all > "%TEMP%\ipconfig.txt" start notepad "%TEMP%\ipconfig.txt"

Save the file as "Batch File IP Config Viewer.bat" and run it. The script will use the built-in Windows ipconfig command to gather information about your IP configuration and save it to a text file located at %TEMP%\ipconfig.txt. It will then open the text file in Notepad for easy viewing.

17. Batch File File Organizer.bat - This file will organize files in a specified directory based on their file type. To use it, open Notepad and paste the following code:

arduino
@echo off 
set /p folder=Enter folder path to organize: 
mkdir "%folder%\PDF" 
mkdir "%folder%\DOC" 
mkdir "%folder%\TXT"
mkdir "%folder%\JPG" 
mkdir "%folder%\MP3" 
mkdir "%folder%\OTHER" 
for %%i in ("%folder%\*.*") do
if "%%~xi"==".pdf" move "%%i" "%folder%\PDF" 
if "%%~xi"==".doc" move "%%i" "%folder%\DOC" 
if "%%~xi"==".txt" move "%%i" "%folder%\TXT" 
if "%%~xi"==".jpg" move "%%i" "%folder%\JPG" 
if "%%~xi"==".mp3" move "%%i" "%folder%\MP3" 
if not "%%~xi"=="" move "%%i" "%folder%\OTHER" 
echo Done! 
pause

Save the file as "Batch File File Organizer.bat" and run it. The script will prompt you to enter a folder path to organize. It will then create subdirectories for PDF, DOC, TXT, JPG, MP3, and other files in the specified folder. It will loop through all the files in the specified folder and move them to the appropriate subdirectory based on their file type.

18. Batch File Text File Merger.bat - This file will merge all the text files in a specified directory into a single file. To use it, open Notepad and paste the following code:

bash
@echo off set /p folder=Enter folder path to merge: cd %folder% type *.txt > merged.txt start notepad merged.txt

Save the file as "Batch File Text File Merger.bat" and run it. The script will prompt you to enter a folder path to merge. It will change the current directory to the specified folder, then use the built-in Windows type command to merge all the text files in the folder into a single file named "merged.txt". It will then open the merged file in Notepad for easy viewing.

19. Batch File IP Address Checker.bat - This file will display the IP address of the computer running the script. To use it, open Notepad and paste the following code:

bash
@echo off for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr /i "IPv4 Address"') do set ip=%%i echo Your IP Address is: %ip:~1% pause

20. Save the file as "Batch File IP Address Checker.bat" and run it. The script will use the built-in Windows ipconfig command to get the IPv4 address of the computer running the script. It will then display the IP address in a command prompt window, with any leading whitespace removed, and pause the script to allow you to view the IP address before closing the window.

The CheckDisk.bat batch file can be used to check your hard disk for errors and fix them if necessary. Here's an example of what the batch file might look like:

bash
@echo off echo Checking disk for errors... chkdsk C: /f /r /x pause

Let's break down what each line does:

  • @echo off: This line turns off command echoing, so the commands themselves don't get displayed on the screen as they run.
  • echo Checking disk for errors...: This line displays a message to the user to let them know what's happening.
  • chkdsk C: /f /r /x: This line runs the chkdsk command on the C: drive, with the /f switch to fix any errors found, the /r switch to locate bad sectors and recover readable information, and the /x switch to force the drive to dismount before checking.
  • pause: This line pauses the batch file so the user can read the output from the chkdsk command.

You can customize the batch file to check a different drive or to use different switches depending on your specific needs. Note that running chkdsk can take some time, especially if it needs to fix errors or recover data, so be patient and let it run to completion.

No comments:

Post a Comment