An updated version of my Quick Wins batch file

posted in: Testing | 0

Almost exactly a year ago, I posted about a batch file I had compiled and use daily. Since then, I have amended it, added colour and added some new items. For a copy of the file, simply click here

For the more cautious amongst you, here is the code in it’s entirety:


REM NOTE:- Use [Ctrl] + [Q] to change selected text to be commented out (REM)
@echo off
:: BatchGotAdmin
::-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"="
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B

:gotAdmin
pushd "%CD%"
CD /D "%~dp0"

::--------------------------------------
REM Maximise Screen
@echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
::--------------------------------------
REM Code to enable coloured text for one specific line using the call :command
@Echo Off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)

:resetcolour
@echo off
title PERFORM VARIOUS COMMANDS
color 1f
:prompt
cls
set mytime=%time%
set mydate=%date%
echo.
echo ##################################### Date this was opened: %mydate%
echo # MARK'S QUICK WIN SCRIPT #
echo ##################################### Time this was opened: %mytime%
echo.
echo -------
echo - DNS -
echo -------
echo.
echo Type A - Add QA DNS
echo.
echo Type R - Remove QA DNS
echo.
echo Type F - Flush DNS
echo.
echo Type M - Ping my machine
echo.
echo Type D - Show ALL My DNS
echo.
echo Type S - Show Current DNS
echo.
echo.
REM echo.
REM echo Type P to Ping my.zuto.com
REM echo.
echo ----------
echo - DELETE -
echo ----------
echo Type T - Clear Temp Folder
echo.
echo Type B - Clear Temp Cookies
echo.
echo Type H - Delete History
echo.
echo Type X - Delete Form Data
echo.
echo.
echo ----------
echo - SYSTEM -
echo ----------
echo Type I - Show System Info - (Also creates a text file stored in c:\systeminfo.txt)
echo.
echo.
echo -----------
echo - TESTING -
echo -----------
echo Type W - go Crash a Website
echo.
echo.
echo ---------
echo - OTHER -
echo ---------
echo Type C - go to Command Prompt
echo.
echo Type N - Change colour back to blue and white
echo.
echo Type Q - exit
echo.
echo.
call :colorEcho 0a "Enter a letter of the action you wish to activate"
echo.
set /p answer=
if ‘%answer%’ == ‘a’ goto addqadns
if ‘%answer%’ == ‘A’ goto addqadns
if ‘%answer%’ == ‘r’ goto removeqadns
if ‘%answer%’ == ‘R’ goto removeqadns
if ‘%answer%’ == ‘f’ goto flushdns
if ‘%answer%’ == ‘F’ goto flushdns
if ‘%answer%’ == ‘H’ goto DeleteHistory
if ‘%answer%’ == ‘h’ goto DeleteHistory
if ‘%answer%’ == ‘X’ goto DeleteFormData
if ‘%answer%’ == ‘x’ goto DeleteFormData
if ‘%answer%’ == ‘C’ goto cmd
if ‘%answer%’ == ‘c’ goto cmd
REM if ‘%answer%’ == ‘P’ goto ping
if ‘%answer%’ == ‘p’ goto ping
if ‘%answer%’ == ‘m’ goto pingmymachine
if ‘%answer%’ == ‘M’ goto pingmymachine
if ‘%answer%’ == ‘d’ goto whatsmydns
if ‘%answer%’ == ‘D’ goto whatsmydns
if ‘%answer%’ == ‘t’ goto cleartempfolder
if ‘%answer%’ == ‘T’ goto cleartempfolder
if ‘%answer%’ == ‘b’ goto cleartempcookies
if ‘%answer%’ == ‘B’ goto cleartempcookies
if ‘%answer%’ == ‘s’ goto showdns
if ‘%answer%’ == ‘S’ goto showdns
if ‘%answer%’ == ‘w’ goto crashwebsite
if ‘%answer%’ == ‘W’ goto crashwebsite
if ‘%answer%’ == ‘n’ goto colour
if ‘%answer%’ == ‘N’ goto colour
if ‘%answer%’ == ‘q’ goto quit
if ‘%answer%’ == ‘Q’ goto quit
if ‘%answer%’ == ‘i’ goto systeminfo
if ‘%answer%’ == ‘I’ goto systeminfo

pause >nul
:addqadns
cls
color 2f
echo -----------------
echo - Add QA DNS... -
echo -----------------
ipconfig /flushdns
REM netsh interface ipv4 set dns name="Local Area Connection" source=static addr=10.128.12.4
REM netsh interface ipv4 add dns name = "Local Area Connection" addr=10.128.12.5
netsh interface ipv4 set dns name="Wi-Fi" source=static addr=
netsh interface ipv4 add dns name = "Wi-Fi" addr=
echo DNS IP Addresses changed to QA.
echo.
echo -------------------
echo - FLUSHING DNS... -
echo -------------------
ipconfig /flushdns >null
echo.
echo DNS Flushed!
echo.
echo ---------------------
echo Heres Your Status...
echo ---------------------
REM ipconfig /all | find "DNS Servers"
echo.
netsh interface ip show dnsservers "Wi-Fi"
echo.
@echo off
set mydate=%date%
set mytime=%time%
echo Current date is %mydate%
echo Current time is %mytime%
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

:removeqadns
cls
color 4f
echo --------------------
echo - Remove QA DNS... -
echo --------------------
ipconfig /flushdns
echo netsh interface ipv4 set dns name="Local Area Connection" dhcp
netsh interface ipv4 set dns name="Wi-Fi" dhcp
echo.
echo QA DNS has now been removed and you are now using LIVE!
echo.
echo -------------------
echo - FLUSHING DNS... -
echo -------------------
ipconfig /flushdns >null
echo.
echo DNS Flushed!
echo.
echo ---------------------
echo Heres Your Status...
echo ---------------------
echo.
echo REM ipconfig /all | find "DNS Servers"
echo.
netsh interface ip show dnsservers "Wi-Fi"
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:flushdns
cls
echo -------------------
echo - FLUSHING DNS... -
echo -------------------
ipconfig /flushdns >nul
echo.
echo DNS Flushed!
echo.
echo ---------------------
echo Heres Your Status...
echo ---------------------
REM ipconfig /all | find "DNS Servers"
echo.
netsh interface ip show dnsservers "Wi-Fi"
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

REM :ping
REM cls
REM echo -------------------------
REM echo - Starting Ping Test... -
REM echo -------------------------
REM echo.
REM ping REM echo.
REM echo Press Any Key to goto MENU
REM pause >null
REM goto prompt

:pingmymachine
cls
echo -------------------------
echo - Starting Ping Test... -
echo -------------------------
echo.
ping
echo.
echo Press Any Key to goto MENU
pause >null
goto prompt

:Whatsmydns
cls
echo ------------------
echo - What's My DNS -
echo ------------------
echo.
REM ipconfig /all | find "DNS Servers"
echo.
netsh interface ip show dnsservers "Wi-Fi"
echo.
echo Press Any Key to goto MENU
pause >null
goto prompt

:showdns
cls
echo ----------------------------
echo - DISPLAY ALL DNS... -
echo ----------------------------
echo.
ipconfig /displaydns
pause
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:cleartempfolder
cls
echo ------------------------
echo - CLEAR TEMP FOLDER... -
echo ------------------------
echo.
echo DELETE LOCAL TEMP FOLDER
cd C:\Users\\AppData\Local
rmdir /S /Q Temp
echo.
echo Done!
echo.
echo Delete Temporary Internet Files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
echo.
echo Temporary files that are not in use have been deleted!
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:cleartempcookies
cls
echo -------------------------
echo - CLEAR TEMP COOKIES... -
echo -------------------------

@echo Delete Cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
del C:\Users\\AppData\Local\Temp\*.*
for /D %%I in ("C:\Users\\AppData\Local\Temp\*") do rmdir /s/q "%%I"
@echo Full list of commands can be found here http://www.thewindowsclub.com/rundll32-shortcut-commands-windows
echo.
echo All temp cookies are now deleted!
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:DeleteHistory
cls
echo -------------------------
echo - DELETE HISTORY... -
echo -------------------------
echo.

@echo Delete History:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

echo.
echo History now deleted!
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:DeleteFormData
cls
echo -------------------------
echo - DELETE FORM DATA... -
echo -------------------------
echo.

@echo Delete Form Data:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

echo.
echo Form meta now deleted.
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:quit
cls
echo Thanks For Using Mark's Awesome Script
pause
exit

:cmd
cls
start "New Window" cmd.exe /k "color 0e"
goto resetcolour

:crashwebsite
@echo off
Title Website Crasher
color 0e
echo Enter the website you would like to crash
set input=
set /p input= Enter your Website here:
if %input%==goto crashwebsite if NOT B
echo Processing Your request
ping localhost>nul
echo To end Crashing press CTRL + C
ping localhost>nul
cls
echo ----------------------------------------------------------------------
echo Now Crashing Website...DO NOT CLOSE THIS BOX!! PRESS CRTL + C TO END!!
echo ----------------------------------------------------------------------
ping %input% -t -l 1000
goto prompt

:colour
Title Changing colour back to the default
color 1f
goto prompt

:systeminfo
start "System Information" cmd.exe /k "color 0e&&systeminfo&&systeminfo>C:\systeminfo.txt"
echo.
echo A text file "systeminfo.txt" has been created in the C:\ folder.
echo.
echo.
echo Press Any Key to Go To Menu
pause >null
goto prompt

:colorEcho
echo off
"%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

Leave a Reply