My Quick Win Commands Bat File

posted in: Software Testing | 0

.Bat File For performing quick commandsAs a QA, I often find myself switching between the QA environment and the Live environment. There are many methods for doing this via host file entries, Proxy switches or the simplest, which is to change your DNS.

To do this manually in Windows means going the start menu, going to the control panel, selecting Network and Sharing Center and the clicking on Change Adapter Settings, then your local area connection. Your still not complete though as you then need to click properties and select Internet protocol version 4 (TCP/IPv4) and then you can change the DNS settings!

With a .bat file, I can do all this in mere seconds and even delete cookies & flush the dns to speed up the change.

A batch file is an unformatted text file that contains one or more commands and has a .bat or .cmd file name extension. When you type the file name at the command prompt, Cmd.exe runs the commands sequentially as they appear in the file. You can include any command in a batch file.

To get you started you need to replace the text in <> with the relevant data; Mainly ip addresses; I have coloured these in blue.


rem This script allows you to change the DNS to & from QA, Flush the DNS, send a ping to my site or open the command prompt

@echo off
title PERFORM VARIOUS COMMANDS
:prompt
color 1f
cls
echo.
echo -------------------------------------
echo - MARK'S QUICK WIN SCRIPT -
echo -------------------------------------
echo.
echo Type A to Add QA DNS
echo.
echo Type R to Remove QA DNS
echo.
echo Type F to Flush DNS
echo.
echo Type P to Ping MY.SITE.COM
echo.
echo Type M to Ping my machine
echo.
echo Type D to What's My DNS
echo.
echo Type S to Show DNS
echo.
echo Type T to Clear Temp Folder
echo.
echo Type B to Clear Temp Cookies
echo.
echo Type H to Delete History
echo.
echo Type X to Delete Form Data
echo.
echo Type C to go to Command Prompt
echo.
echo Type Q to exit
echo.
set /p answer=
if ‘%answer%’ == ‘a’ goto addqadns
if ‘%answer%’ == ‘A’ goto addqadns
if ‘%answer%’ == ‘r’ goto removeqadns
if ‘%answer%’ == ‘R’ goto rmeoveqadns
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
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%’ == ‘q’ goto quit
if ‘%answer%’ == ‘Q’ goto quit

pause >nul

:addqadns
cls
echo -----------------
echo - Add QA DNS... -
echo -----------------
ipconfig /flushdns
netsh interface ipv4 set dns name=”Local Area Connection” source=static addr=<IP ADDRESS YOU WANT TO ADD IN THE DNS>
netsh interface ipv4 add dns name = “Local Area Connection” addr=<IP ADDRESS YOU WANT TO ADD IN THE DNS>
echo.
echo Done!
echo.
echo -------------------
echo - FLUSHING DNS... -
echo -------------------
ipconfig /flushdns >nul
echo.
echo DNS Flushed!
echo.
echo ---------------------
echo Heres Your Status...
echo ---------------------
echo.
ipconfig /all
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

:removeqadns
cls
echo --------------------
echo - Remove QA DNS... -
echo --------------------
ipconfig /flushdns
netsh interface ipv4 set dns name="Local Area Connection" dhcp
echo.
echo Done!
echo.
echo -------------------
echo - FLUSHING DNS... -
echo -------------------
ipconfig /flushdns >nul
echo.
echo DNS Flushed!
echo.
echo ---------------------
echo Heres Your Status...
echo ---------------------
echo.
ipconfig /all
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

:ping
cls
echo -------------------------
echo - Starting Ping Test... -
echo -------------------------
echo.
ping MY.SITE.COM
echo.
echo Press Any Key to goto MENU
pause >nul
goto prompt

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

:Whatsmydns
cls
echo ----------------------------------
echo - Starting What's My DNS Test... -
echo ----------------------------------
echo.
ipconfig /all
echo.
echo Press Any Key to goto MENU
pause >nul
goto prompt

:flushdns
cls
echo -------------------
echo - FLUSHING DNS... -
echo -------------------
ipconfig /flushdns >nul
echo.
echo Done!
echo.
echo ---------------------
echo Heres Your Status...
echo ---------------------
ipconfig /all
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

:cleartempfolder
cls
echo ------------------------
echo - CLEAR TEMP FOLDER... -
echo ------------------------
echo.
echo DELETE LOCAL TEMP FOLDER
cd C:\Users\<USERNAME>\AppData\Local
rmdir /S /Q Temp
echo.
echo Done!
echo.
echo Delete Temporary Internet Files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
echo.
echo Done!
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

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

@echo Delete Cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

del C:\Users\<NT LOGIN NAME>\AppData\Local\Temp\*.*

for /D %%I in ("C:\Users\<NT LOGIN NAME>\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 Done!
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

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

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

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

echo.
echo Done!
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

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

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

echo.
echo Done!
echo.
echo Press Any Key to Go To Menu
pause >nul
goto prompt

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

:cmd
@color 7
cls
cmd
@echo on

Simply put this code into a text document and then save as mybatfilename.bat 

When you run it, right click on it and run as administrator, then you can leave it open until you need it.

Here’s the Quick Commands Bat File to download to make your life easier.

 

Enjoy!

Leave a Reply