Pinterest Stumbleupon Whatsapp

Batch files are the computer handyman’s way of getting things done. They can automate everyday tasks, shorten the required time to do something, and translate a complex process into something anyone could operate.

In this article, I’ll show you how to write a simple batch file. You’ll learn the basics of what batch files can do and how to write them yourself. I’ll also provide you with further resources for learning to write batch (BAT) files.

Step 1: Create a BAT File

Let’s say that you frequently have network issues; you constantly find yourself on the command prompt A Beginners Guide To The Windows Command Line A Beginners Guide To The Windows Command Line Read More , typing in ipconfig and pinging Google to troubleshoot network problems. After a while you realize that it would be a bit more efficient if you just wrote a simple BAT file, stuck it on your USB stick, and used it on the machines you troubleshoot.

Create a New Text Document

A batch file simplifies repeatable computer tasks using the Windows command prompt. Below is an example of a batch file responsible for displaying some text in your command prompt. Create a new BAT file by right-clicking an empty space within a directory and selecting New, then Text Document.

new_text_file

Add Code

Double-click this New Text Document to open your default text editor. Copy and paste the following code into your text entry.

@echo off
title This is your first batch script!
echo Welcome to batch scripting!
pause

Save As BAT File

The above script echoes back the text “Welcome to batch scripting!”. Save your file by heading to File, Save As, and then name your file what you’d like. End your file name with the added .bat extension — welcome.bat for example — and click OK. This will finalize the batch process. Now,  double-click on your newly created batch file to activate it.

welcome_to_batch

Don’t assume that’s all batch scripting can do. Batch scripts parameters are tweaked versions of command prompt codes, so you are only limited to what your command prompt can do. For those unfamiliar the program, command prompt is capable of quite a lot 15 CMD Commands Every Windows User Should Know 15 CMD Commands Every Windows User Should Know The command prompt is an antiquated tool from an era of text-based input. But some commands remain useful and Windows 8 even added new features. Find out which ones. Read More .

Step 2: Learn Some Quick Code

If you know how to run commands in the command prompt, you’ll be a wiz at creating BAT files because it’s the same language. All you’re doing is telling the command prompt what you want to input through a file, rather than typing it out in the command prompt. This saves you time and effort; but it also allows you to put in some logic (like simple loops, conditional statements, etc. that procedural programming is capable of conceptually).

@echo — This parameter will allow you to view your working script in the command prompt. This parameter is useful for viewing your working code. If any issues arise from the batch file, you will be able to view the issues associated with your script using the echo function. Adding a following off to this parameter will allow you to quickly close your script after it has finished.

title — Providing much of the same function as a <title> tag in HTML, this will provide a title for your batch script in your Command Prompt window.

cls — Clears your command prompt, best used when extraneous code can make what you’re accessing had to find.

rem — Shorthand for remark, provides the same functionality as <!– tag in HTML. Rem statements are not entered into your code. Instead, they are used to explain and give information regarding the code.

%%a — Each file in the folder.

(“.\”) — The root folder. When using the command prompt, one must direct the prompt to a particular directory before changing a files name, deleting a file, and so on. With batch files, you only need to paste your .bat file into the directory of your choosing.

pause — Allows a break in the logical chain of your .bat file. This allows for users to read over command lines before proceeding with the code. The phrase “Press any key to continue…” will denote a pause.

start “” [website] — Will head to a website of your choice using your default web browser.

ipconfig — This is a classic command prompt parameter that releases information concerning network information. This information includes MAC addresses, IP addresses, and sub-net masks.

ping — Pings an IP address, sending data packets through server routes to gauge their location and latency (response time).

The library for batch variables is huge, to say the least. Luckily there is a Wikibook entry which holds the extensive library of batch script parameters and variables at your disposal.

Step 3: Write & Run Your BAT File

We’ll create two examples of batch scripts which can simplify your daily online and offline activities.

News Script

Let’s create an immediately useful batch script. What if you wanted to open all your favorite news websites Read More Intelligent Content in 2016 with These 35 Sites Read More Intelligent Content in 2016 with These 35 Sites We should all read these 35 sites more often. If you are tiring of dumbed-down content make things somewhat more thoughtful this coming year with this super list. Read More the moment you wake up? Since batch scripts use command prompt parameters, we can create a script that opens every news media outlet in a single browser window.

To re-iterate the batch-making process: first, create an empty text file. Right-click an empty space in a folder of your choosing, and select New, then Text Document. With the text file open, enter the following script. Our example will provide the main American news media outlets available online.

@echo off
start "" http://www.cnn.com
start "" http://www.abc.com
start "" http://www.msnbc.com
start "" http://www.bbc.com
start "" http://www.huffingtonpost.com
start "" http://www.aljazeera.com
start "" https://news.google.com/

The above script stacks one start “” parameter on top of the other to open multiple tabs. You can replace the links provided with ones of your choosing. After you’ve entered the script, head to File, then Save As. In the Save As window, save your file with the .bat extension and change the Save as type parameter to All Files (*.*).

save_as_bat

Once you’d saved your file, all you need to do is double-click your BAT file. Instantly, your web pages will open. If you’d like, you can place this file on your desktop. This will allow you to access all of your favorite websites at once.

File Organizer

Have you been downloading multiple files a day, only to have hundreds of files clogging up your Download folder? Create a batch file with the following script, which orders your files by file type.  Place the .bat file into your disorganized folder, and double-click to run.

@echo off
rem For each file in your folder
for %%a in (".\*") do (
rem check if the file has an extension and if it is not our script
if "%%~xa" NEQ ""  if "%%~dpxa" NEQ "%~dpx0" (
rem check if extension folder exists, if not it is created
if not exist "%%~xa" mkdir "%%~xa"
rem Move the file to directory
move "%%a" "%%~dpa%%~xa\"
))

Here is an example of the my desktop before, a loose assortment of image files.

assorted_files

Here are those same files afterward.

ordered_files

It’s that simple. This batch script will also work with any type of file, whether it’s a document, video, or audio file. Even if your PC does not support the file format, the script will create a folder with the appropriate label for you. If you already have a JPG or PNG folder in your directory, the script will simply move your file types to their appropriate location.

Automate the Simple Stuff

This is just a taste of what batch scripts have to offer. If you need something simple done over and over — whether it be ordering files, opening multiple web pages, renaming files en masse How to Batch Rename & Mass Delete Files in Windows How to Batch Rename & Mass Delete Files in Windows Are you pulling your hair out over how to batch rename or delete hundreds or thousands of files? Chances are, someone else is already bald and figured it out. We show you all the tricks. Read More , or creating copies of important documents — you can make tedious tasks simple with batch scripts.

Do you use batch scripts? If so, what task do you automate? Let us know in the comments below!

Originally written by Paul Bozzay on March 24, 2010.

  1. Ian G
    November 18, 2016 at 3:35 am

    never written a batch file before . something new that I've Learned on my 73rd Birthday youre never too old to learn :)

    • Tina Sieber
      November 28, 2016 at 12:42 pm

      Thank you for your feedback, Ian! Glad this article still makes it easy for people to write their first batch file. :)

  2. Pradeep Kumar Jee
    September 20, 2016 at 1:29 pm

    Thanks a lot .I had a unreasonable fear of bat files.Your write up cleared it

  3. diabloIIIROS
    August 27, 2016 at 3:43 am

    can i make a .bat file so its like i am pressing a button on the keyboard but I am not the file does it for me like a auto clicker but instead a auto button clicker?

  4. Yasintha Kosala
    August 21, 2016 at 2:51 pm

    Thank you very much for such a valuable article.

  5. Vaishak
    August 4, 2016 at 10:42 am

    Really enjoyed reading and actually running my first BAT file. Thanks a lot mate. Cant thank you enough.

  6. swati sawant
    July 27, 2016 at 5:57 am

    Its very simple and clear...thanks..

  7. brady
    July 23, 2016 at 3:15 pm

    my command opens and closes instanly

    • prathap badavath
      August 11, 2016 at 6:08 pm

      add pause command at end of the file

  8. sudhakar
    July 14, 2016 at 7:07 am

    Pretty cool stuff! thanks a lot! am excited to learn the bat file creation!!

  9. sanjay Tanti
    July 3, 2016 at 6:54 am

    Nice ... thanks

  10. Connor Glogowski
    July 2, 2016 at 1:15 am

    Oh

  11. Connor Glogowski
    July 2, 2016 at 1:15 am

    NOOOOOOOOO

  12. Connor Glogowski
    July 2, 2016 at 12:04 am

    I'm gonna save this website thanks!

  13. ayyappa
    June 8, 2016 at 5:29 pm

    Thanks...

  14. jayanthsaikiran
    June 6, 2016 at 4:17 pm

    thanks for some quick tips. love #makeuseof

  15. rajesh
    May 25, 2016 at 7:24 am

    i want to copy 1 file from network pc to my pc. what will be command?. please help...

    • Dude1234
      June 2, 2016 at 7:36 pm

      I think your too retarded for that

      • bob
        July 15, 2016 at 4:53 pm

        *you're

  16. Nat Pagle
    May 23, 2016 at 9:09 pm

    I used it to start an administrator command prompt without having to right click or create a shortcut and modify the properties.

    powershell.exe -Command "Start-Process cmd -Verb RunAs"
    exit

  17. Ramu
    May 20, 2016 at 11:14 am

    Thank you paul it was really help full for me as a biginner

  18. Israel Jacob
    April 18, 2016 at 1:19 pm

    Thanks for sharing this information! It was just what I needed.

  19. abc
    April 14, 2016 at 7:16 am

    I have no idea of programming. I am trying to compress all the files in the folder automatically for the pervious month. How can we do thjis?

  20. adel
    April 13, 2016 at 9:10 am

    in case i want to copy all the contents in c:\allfile and D:\allfiles to external disk how should the command appear

    xcopy c:\users\%username% E:\user data\ /o /x /e /h /k
    xcopy d:\ e:\user data\d /o /x /e /h /k

    PAUSE?

  21. santhosh
    March 14, 2016 at 7:18 am

    Hi

    I need to run commands in karaf shell once it is started by batch file. how to invoke karaf cmd instead of windows cmd

    Thanks.

  22. Dominic
    March 3, 2016 at 8:48 pm

    I created a simple batch file for starting one of our common .jar file installers however after the installation is complete the only thing showing in the folder where the log file is located is an empty log file.

    Ex: start java.exe -DFORCE_OVERRIDE_PRE_REQ=true -jar %~dp0install_||||_x.x.x.x.x.jar 1>%~dp0install_||||_x.x.x.x.x.log 2>&1

    How do I write this so that the log file actually records the install process from start to finish?

    Keep in mind I have been at writing batch files for all of about 1 week.

    • Varun
      April 6, 2016 at 3:10 pm

      Hi Dominic,

      Did you get the script for capturing the log file. Appreciate if you could share.

      • Dominic Casey
        April 6, 2016 at 4:36 pm

        Hello Varun,

        The fix for my issue is to simply run the batch file from the folder where the .jar file is located. I was running the batch from outside the folder which caused the issue.

        Dom

  23. Rajesh
    February 24, 2016 at 4:41 pm

    guys anyone help me out to copy the files from the desktop in the back end with the bat file please help me out

    • Thanes
      April 14, 2016 at 3:17 am

      source_file copy destination_location

  24. limani mithu
    February 2, 2016 at 6:52 am

    Thanks for sharing i really wonder for this .bat file command thanks for sharing..

    this blog may be helps you to find some technology tips and tricks... 1storiginal.com

  25. Bored
    January 20, 2016 at 8:13 pm

    Hello every one.

    is it possible when i type a website, bat file will automatically execute?

  26. Ed
    January 12, 2016 at 5:43 pm

    I need to create a batch file to allow a colleague to load multiple jpegs to a site. The jpegs are on my local drive and my colleague is a 3rd party vendor.

    My questions are:
    1. do i need to load these jpeg files onto a shared server
    2. I was told to use the "Xref" command... can someone walk me through this or is there a better command/solution?

    Thanks!

  27. DK
    January 8, 2016 at 3:11 pm

    I have two monitors set up, one for gaming and a larger TV for watching movies. Often times I only want to use one, so I made a few .bat files and set them up as "Launch Program" hotkeys on my Razer keyboard. Basically hitting M1 shuts off the secondary monitor, and M2 turns on the second display.

    Main.bat
    %windir%\System32\DisplaySwitch.exe /external

    Extend.bat
    %windir%\System32\DisplaySwitch.exe /extend

    By default, the secondary display becomes primary, most likely because of the Display settings in Windows, it seems to remember which one is supposed to be primary.

  28. Matt
    December 24, 2015 at 12:20 am

    ECHO OFF
    ::
    ECHO
    ::
    REG add "HKCU\Control Panel\Desktop" /v ForegroundLockTimeout /t REG_DWORD /d 0 /f
    REG add "HKCU\Control Panel\Desktop" /v MenuShowDelay /t REG_SZ /d 100 /f
    REG add "HKLM\SYSTEM\CurrentControlSet\Control" /v WaitToKillServiceTimeout /t REG_SZ /d 5000 /f
    ::
    cd \
    md startupfolderbackup
    cd windows
    cd "start menu"
    cd programs
    cd startup
    dir /w
    ::
    ipconfig /flushdns
    ::
    PAUSE
    ::
    sfc /scannow

  29. stephen
    December 19, 2015 at 5:13 am

    I am also created a batch file successfully But it asking administrator mode.what i do now?

    • stephen
      December 19, 2015 at 5:18 am

      here my batch file...

      @echo off
      netsh wlan start hostednetwork
      pause

      • Roshan
        January 15, 2016 at 2:03 am

        @echo off
        netsh wlan set hostednetwork mode=allow ssid=stephen key=password
        netsh wlan start hostednetwork

        and save it as a wifi.bat file

        and now write click on file and click on Run as Administrator

        now go to ur wifi and shared ur wifi

  30. Rob Ross
    December 16, 2015 at 6:14 pm

    I created a batch file to backup my Assassin's Creed savegame files. The other night I accidentally started a new game after having previously finished the first big mission and I wanted to gouge my own eyes out. Because I don't have that game on any cloud service there's no automagic backups of my savegame so I realized it would have been great if I had backed up the save so I wrote a quick BAT for my desktop so that when I finish playing, I just double-click the file and the save is backed up -- no more starting from the beginning again!

    I was trying to figure out why it wasn't working, because the last time I wrote a batch file was back during the days of Windows 95, and I thought I'd do some research when I came across this post. It helped to reload my hacker memory with just the description of a few commands, and then I realized that the reason why the code wasn't working was that I had to use quotes around my file paths.

  31. Dasen Xiong
    December 15, 2015 at 4:44 pm

    How do I do this?

    Create a Batch file for Backups
    Create a simple batch file using the x copy command
    Copy the files and sub directories (non-empty) from C:\Data to G:\backup

    i. For the G: drive we are pretending that it would be an external drive that we have connected – we don’t need a G: to be present – but use G:\backup as your destination for the batch file command

    Save the batch file as the following: C:\Batch\Weekly_Backup.bat

  32. Chris
    December 4, 2015 at 11:48 pm

    Great Job !!

  33. douglas420
    December 1, 2015 at 9:10 am

    Really nice guide!

  34. Givious
    November 23, 2015 at 9:39 pm

    Wow! This is really wonderful, I have tried the sample code and its working.
    Thanks for giving me a good start to creating scripts using command prompt
    Big up to you.

  35. Khalid Hossain
    November 20, 2015 at 7:42 am

    Hi There,

    I to get one suggestion, weekly I am taking DB dump for 15 schema. So I want to automate this process.
    For that I created a batch file and it compiles successfully, only need to change date weekly basis.

    Can you please suggest me how to change date automatically in BATCH file and how to put that BATCH file in Windows path, so it takes dump automatically as weekly basis??

    My system: Winsdows 7: 64 bit

    Thanks!

  36. Peter
    November 20, 2015 at 1:54 am

    I tried the test code but I didn't get the PING info. I copied & pasted the code :(

    • Nate
      December 15, 2015 at 12:06 pm

      Peter press enter or pause( any key)it will continue and you will get the ping info

  37. Ravindra Ramaiah
    November 6, 2015 at 1:34 pm

    i tried your sample code, I need your suggestion for this.

    I have 200 folders in D:\dst the names of these 200 folders would be like (X123, Y123, Z123 ....) now i need to copy some of these folders say (X123 and Z123) to a destionation C:\New Folder.

    in my case i need to copy the whole folder rather than a file.

    Please suggest how i can achieve this.

    Thanks | Ravindra.R

  38. Ravindra Ramaiah
    November 6, 2015 at 1:25 pm

    Hi,

  39. Ravi Kumar Neelam
    September 28, 2015 at 7:50 am

    Thanks, you saved me a lot of time

  40. Chris Bethel
    September 21, 2015 at 11:40 am

    Kelly,

    If you are attempting this at your work, its very possible that your company has "deny ICMP messages" implemented on their network devices (router/switch). This is a security blanket for IT professionals to prevent DoS attacks. If you are at home and this is happening, it may be possible that your ISP is preventing the use of ICMP messages? It's hard to tell without really knowing how your computer and network are setup.

  41. gila xes
    September 15, 2015 at 10:52 am

    Thank you very much !!! :)

  42. Shahzad Qureshi
    September 1, 2015 at 5:54 pm

    very nice

  43. Scott Martin
    August 19, 2015 at 8:24 am

    I found this very useful, thank you

  44. Aaron Erickson
    August 3, 2015 at 10:10 pm

    How can I get this to work for the following command?
    for /r %i in (*.dll) do regsvr32 /s "%i"
    Please help

  45. Kelly Seo
    July 31, 2015 at 6:13 am

    Hello!
    I copied and pasted the entire example and.... its running successfully!! (Many thanks!!)
    But I kept getting Request timed out at ping http://www.google.com portion!
    Im am currently connected to the internet and i can do a google search!!

    I tried changing it to PING makeuseof.com but it also shows request timed out!

    Any ideas?

  46. John Smith Images
    May 19, 2015 at 6:08 am

    Well, congrats and thanks. It's always the most basic information that are the most difficult to get and you've done it perfectly.

  47. Kaushal
    May 15, 2015 at 12:04 pm

    I really liked the post.

    After reading the post I would like to implement it in my work to make it easier and less time consuming. Can we update a column in the Database for the bulk of data at once?

    If yes, can you please provide the sample code for it. I would be very thankful for the same.

    Thanks in Advance. Kaushal

  48. Mallinath
    May 8, 2015 at 6:26 pm

    Can anyone help me to create one batch file for connecting VPN automatically. Because we keep selenium test execution in the night. But due to some technical issues the vpn is getting disconnect automatically.

    For our automation testing we have to connect Junos VPN , login with credentials. and it should click on connect. Then my selenium automation script should continue our test execution,

    So I am looking for a script for batch file or java file which should run in selenium web driver.

    Please feel free to share your ideas to me at mallumulage@gmail.com

  49. Khaleel
    March 13, 2015 at 1:02 am

    Hi Nathan,

    When I gave input as 1 and enter, it is returning error like this.

    "ô1ö is not valid please try again" for all the value it is displaying this error. please advice.

    Regards,
    Khaleel

    • kumbaya
      May 13, 2015 at 4:24 pm

      It's because (double and single) quotation marks you've copied from the text are not accepted in windows command prompt. Copy all script to text file and replace these characters:
      “ with "
      ” with "
      ’ with '
      ? with '

  50. Nathan
    March 7, 2015 at 3:20 pm

    Here is a bat file ive been coding in my free time....

    title PC TOOLS (C) Marcus Meyer designed by NATHAN VAN NIEKERK Version 2.0
    @echo off

    color 0c
    cls
    echo (C) Marcus Meyer designed by NATHAN VAN NIEKERK
    echo.
    cls
    goto start

    rem ####################### START ######################
    :start
    echo (C) Marcus Meyer designed by NATHAN VAN NIEKERK
    echo.
    color 0a
    echo %name% WELCOME TO PC TOOLS!!
    echo What option would you like to execute?
    echo.
    echo NETWORKING:
    echo _____________
    echo 1) Ipconfig
    echo 2) Ping an ip address
    echo 3) Trace Root
    echo 4) NetStat
    echo 5) Get Mac address
    echo.
    echo SYSTEM INFO:
    echo ______________
    echo 6) Who am I
    echo 7) PC INFO
    echo 8) Performance Check
    echo 9) Disk Check
    echo 10) Driver Check
    echo 11) Mirror Drive
    echo 12) Recover Drive
    echo.
    echo WINDOWS TOOLS:
    echo __________________
    echo 13) Clear recycle bin and Temporary files
    echo 14) Hard drive Defrag
    echo 15) Start or End a Task
    echo.

    echo 16) Exit

    echo.
    set option=
    echo.
    set /p option=Select One:
    echo.
    if '%option%'=='1' goto ipconfig
    if '%option%'=='2' goto ping
    if '%option%'=='3' goto tracert
    if '%option%'=='4' goto netstat
    if '%option%'=='5' goto getmac
    if '%option%'=='6' goto whoami
    if '%option%'=='7' goto pcinfo
    if '%option%'=='8' goto perfmon
    if '%option%'=='9' goto CHKDSK
    if '%option%'=='10' goto DRIVER
    if '%option%'=='11' goto MIR
    if '%option%'=='12' goto recover
    if '%option%'=='13' goto clearmgr
    if '%option%'=='14' goto defrag
    if '%option%'=='15' goto task
    if '%option%'=='16' goto exit
    echo.
    ECHO "%option%" is not valid please try again
    goto start
    ECHO.

    rem ###################### Options #####################

    rem ###################### ipconfig #######################
    :ipconfig

    color 0c
    echo.
    ipconfig
    pause
    cls
    goto start

    rem ###################### ping #######################
    :ping
    color 0b
    echo If you dont know the ip adress of the target pc, you can find the other target IP Address, by using our program and option 1
    pause
    echo Please enter the IP adress you would like to ping?
    echo.
    Set /p ip=
    ping %ip%
    pause
    cls
    goto start

    rem ###################### tracert #######################
    :tracert
    color 0b
    echo Please enter web page you would like to trace?
    echo.
    Set /p trace=
    echo.
    echo Trace Root initiate
    tracert %trace%
    pause
    cls
    goto start

    rem ###################### netstat #######################
    :netstat
    color 0f
    echo.
    netstat
    pause
    cls
    goto start

    rem ###################### getmac #######################
    :getmac
    @echo off
    color 0e
    echo.
    getmac
    echo.
    echo Have you got all the info needed?
    pause
    cls
    goto start

    rem ###################### whoami #######################
    :whoami
    color 0d
    whoami
    pause
    cls
    goto start

    rem ###################### pcinfo #######################
    :pcinfo
    color 0e
    systeminfo
    pause
    cls
    goto start

    rem ###################### clearmgr#######################
    :clearmgr
    echo Just follow the On Screen instructions and Press OK, Press Delete and OK.
    CleanMgr
    echo DONE!!
    pause
    cls
    goto start

    rem ###################### defrag #######################
    :defrag
    echo You will need to run this program as Administrator
    echo This will Defrag all volumes:
    pause
    defrag /C /H /V
    pause
    cls
    goto start

    rem ###################### perfmon #######################
    :perfmon
    color 0b
    echo.
    echo Please wait program starting...
    PERFMON
    pause
    cls
    goto start

    rem ###################### CHKDSK#######################
    :CHKDSK
    echo Please enter the drive you would like to check?
    echo.
    Set /p DSK=
    echo.
    cls
    echo Check disk initiate
    CHKDSK %DSK%:
    pause
    cls
    goto start
    rem ###################### DRIVER#######################
    :DRIVER
    DRIVERQUERY
    pause
    cls
    goto start

    rem ###################### MIR #######################
    :MIR

    color 0c
    echo Please Enter the Source DRIVE
    echo.
    set /p SOURCE=
    echo Please Enter the Destination DRIVE
    echo.
    set /p DEST=
    ROBOCOPY %SOURCE%: %DEST%: /MIR
    pause
    cls
    goto start

    rem ###################### recover #######################
    :recover
    echo Please Enter the Source file path
    echo.
    set /p SOURCE=
    TYPE SOURCE
    pause
    cls
    goto start

    rem ###################### task #######################
    :task
    cls
    echo TASK KILL OR START TASK MENU
    echo.
    echo What option would you like to execute?
    echo.
    echo 1) Task Kill
    echo 2) start task
    echo 3) back

    echo.
    set option=
    echo.
    set /p option=Select One:
    echo.

    if '%option%'=='1' goto taskkill
    if '%option%'=='2' goto starttask
    if '%option%'=='3' goto back

    ################# taskkill ###################
    :taskkill
    echo What process would you like to end?
    echo.
    set /p task_name= task name without .exe
    taskkill /f /im %task_name%.exe
    pause
    cls
    goto task

    ################# starttask ###################
    :starttask
    echo What process would you like to start?
    echo.
    set /p task_name=
    start %task_name%

    cls
    pause
    goto task..

    ################# back ###################
    :back
    cls
    goto start

    rem ###################### exit #######################
    :exit
    echo Are you sure you want to EXIT?
    pause
    exit

    • João
      March 8, 2015 at 1:02 am

      I take de liberty to change a litle your batch file.
      i wope you don't mind .
      you can add those if you want:
      displaydns
      flush dns
      ipconfig/realese
      ipconfig/renew
      routeprint
      and remote assistant as well
      title PC TOOLS (C) Marcus Meyer designed by NATHAN VAN NIEKERK Version 2.0
      mode 48,40
      @echo off
      color 0c
      cls
      echo (C) Marcus Meyer designed by NATHAN VAN NIEKERK
      echo.
      cls
      goto start
      rem ####################### START ######################
      :start
      echo (C) Marcus Meyer designed by NATHAN VAN NIEKERK
      echo.
      mode 48,40
      color 0a
      echo %username% WELCOME TO PC TOOLS!!
      echo What option would you like to execute?
      echo.
      echo NETWORKING:
      echo _____________
      echo 1) Ipconfig
      echo 2) Ping an ip address
      echo 3) Trace Root
      echo 4) NetStat
      echo 5) Get Mac address
      echo.
      echo SYSTEM INFO:
      echo ______________
      echo 6) Who am I
      echo 7) PC INFO
      echo 8) Performance Check
      echo 9) Disk Check
      echo 10) Driver Check
      echo 11) Mirror Drive
      echo 12) Recover Drive
      echo.
      echo WINDOWS TOOLS:
      echo __________________
      echo 13) Clear recycle bin and Temporary files
      echo 14) Hard drive Defrag
      echo 15) Start or End a Task
      echo.
      echo 16) Exit
      echo.
      set option=
      echo.
      set /p option=Select One:
      echo.
      if "%option%"=="1" goto ipconfig
      if "%option%"=="2" goto ping
      if "%option%"=="3" goto tracert
      if "%option%"=="4" goto netstat
      if "%option%"=="5" goto getmac
      if "%option%"=="6" goto whoami
      if "%option%"=="7" goto pcinfo
      if "%option%"=="8" goto perfmon
      if "%option%"=="9" goto CHKDSK
      if "%option%"=="10" goto DRIVER
      if "%option%"=="11" goto MIR
      if "%option%"=="12" goto recover
      if "%option%"=="13" goto clearmgr
      if "%option%"=="14" goto defrag
      if "%option%"=="15" goto task
      if "%option%"=="16" goto exit
      echo.
      ECHO “%option%” is not valid please try again
      goto start
      ECHO.
      rem ###################### Options #####################
      rem ###################### ipconfig #######################
      :ipconfig
      mode 70,40
      cls
      color 0c
      echo.
      ipconfig
      pause
      cls
      goto start
      rem ###################### ping #######################
      :ping
      cls
      color 0b
      @echo off
      mode 45,2
      color 0F
      set /p a="Enter IP ADDRESS: "
      MODE 60,15
      ping %a%
      echo [----------------------------------------------------------]
      pause
      cls
      goto start
      rem ###################### tracert #######################
      :tracert
      mode 60,5
      cls
      color 0b
      echo Please enter web page you would like to trace?
      echo [EXAMPLE] http://www.google.com
      echo.
      Set /p trace=
      mode 75,50
      echo.
      echo Trace Root initiate
      tracert %trace%
      pause
      cls
      goto start
      rem ###################### netstat #######################
      :netstat
      @echo off
      color 0F
      :options
      mode 45,10
      cls
      echo MENU OPTIONS:
      echo =====================
      echo a All links
      echo e Ethernet Statistics
      echo f Displays FDQN
      echo n Addresses and ports
      echo =====================
      echo q to quit
      echo =====================
      set /p input="Enter Options Here: "

      if "%input%"=="a" goto:a
      if "%input%"=="e" goto:e
      if "%input%"=="f" goto:f
      if "%input%"=="n" goto:n
      if "%input%"=="q" goto:start

      echo Please choose from the Options listed above!
      pause
      goto:options

      :a
      mode 80,60
      netstat.exe -a
      pause
      goto:options

      :e
      mode 80,15
      netstat.exe -e
      pause
      goto:options

      :f
      mode 80,25
      netstat.exe -f
      pause
      goto:options

      :n
      mode 80,20
      netstat.exe -n
      pause
      goto:options
      rem ###################### getmac #######################
      :getmac
      mode 60,25
      @echo off
      cls
      color 0e
      echo.
      arp -a
      echo.
      echo Have you got all the info needed?
      pause
      cls
      goto start
      rem ###################### whoami #######################
      :whoami
      mode 45,5
      color 0d
      whoami
      pause
      cls
      goto start
      rem ###################### pcinfo #######################
      :pcinfo
      mode 80,60
      cls
      color 0e
      systeminfo
      pause
      cls
      goto start
      rem ###################### perfmon #######################
      :perfmon
      mode 45,5
      cls
      color 0b
      echo.
      echo Please wait program starting!
      PERFMON
      pause
      cls
      goto start
      rem ###################### CHKDSK#######################
      :CHKDSK
      mode 48,5
      cls
      echo Please enter the drive you would like to check?
      echo.
      Set /p DSK=
      echo.
      cls
      echo Check disk initiate
      CHKDSK %DSK%:
      pause
      cls
      goto start
      rem ###################### clearmgr#######################
      :clearmgr
      echo Just follow the On Screen instructions and Press OK, Press Delete and OK.
      CleanMgr
      echo DONE!!
      pause
      cls
      goto start
      rem ###################### defrag #######################
      :defrag
      echo You will need to run this program as Administrator
      echo This will Defrag all volumes:
      pause
      defrag /C /H /V
      pause
      cls
      goto start

      rem ###################### DRIVER#######################
      :DRIVER
      mode 48,50
      cls
      DRIVERQUERY
      pause
      cls
      goto start
      rem ###################### MIR #######################
      :MIR
      color 0c
      echo Please Enter the Source DRIVE
      echo.
      set /p SOURCE=
      echo Please Enter the Destination DRIVE
      echo.
      set /p DEST=
      ROBOCOPY %SOURCE%: %DEST%: /MIR
      pause
      cls
      goto start
      rem ###################### recover #######################
      :recover
      echo Please Enter the Source file path
      echo.
      set /p SOURCE=
      TYPE SOURCE
      pause
      cls
      goto start
      rem ###################### task #######################
      :task
      mode 40,10
      cls
      echo TASK KILL OR START TASK MENU
      echo.
      echo What option would you like to execute?
      echo.
      echo T) Tasklist
      echo 1) Task Kill
      echo 2) start task
      echo 3) back
      echo.
      set option=
      echo.
      set /p option=Select One:
      echo.
      if "%option%"=="T" goto tasklist
      if "%option%"=="1" goto taskkill
      if "%option%"=="2" goto starttask
      if "%option%"=="3" goto back
      ################# tasklist ###################
      :tasklist
      mode 48,50
      cls
      echo The fowlling process are actives!
      tasklist
      pause
      cls
      goto task
      ################# taskkill ###################
      :taskkill
      echo What process would you like to end?
      echo.
      set /p task_name= task name without .exe
      taskkill /f /im %task_name%.exe
      pause
      cls
      goto task
      ################# starttask ###################
      :starttask
      echo What process would you like to start?
      echo.
      set /p task_name=
      start %task_name%
      cls
      pause
      goto task..
      ################# back ###################
      :back
      cls
      goto start
      ###################### exit #######################
      :exit
      mode 45,5
      cls
      echo Are you sure you want to EXIT?
      echo Select c to cancel or press ok to exit
      set /p input="Enter Options Here: "
      if "%input%"=="ok" goto:ok
      if "%input%"=="c" goto:start

  51. ABDUL WAJID
    March 7, 2015 at 10:51 am

    Hey! can eny1 help me out to create a .bat file, which if i will put it in a folder with lots of data & open it it repeats the same folder where the bat file is, because my friend once did it with me during my school days but i forgot to ask him so eny1 plz hlp
    & also if there is eny program that if i click the bat file the computer will go to sleep automatically, if some program like that is there plz inform me.

  52. Johnny Hamrick
    February 13, 2015 at 5:06 pm

    Here is a fun batch file. Type:
    Title VIRUS
    Color 02
    echo off
    cls

    echo VIRUS DETECTED
    pause
    cls
    echo DO YOU WISH TO DELETE VIRUS? (Y/N)
    pause
    cls
    echo DELETING ALL FILES
    pause
    cls
    echo MICROSOFT PROGRAM DELETED
    Pause
    echo GOODBYE
    pause
    cls

    • Dan
      February 13, 2015 at 7:26 pm

      Why even use a cls at the end? The user probably wouldn't even notice it. Funny idea though.

    • Johnny Hamrick
      February 13, 2015 at 7:51 pm

      Well another thing you could do is disguise it as their main internet icon so that whenever they click on it this will always pop up. I did that to a friend they couldn't figure it out.

    • Dan
      February 13, 2015 at 8:03 pm

      lol, I'll have to try that sometime. Might want to go with a bright red instead of green, color b or color c I believe.

    • Johnny Hamrick
      February 15, 2015 at 5:37 pm

      The reason I picked 02 was for a black background with a red font. It appears better than some other combinations that I have seen.

    • Nathan
      March 7, 2015 at 3:28 pm

      Here is a tweek to your prank.....
      Title VIRUS
      Color 02
      echo off
      cls
      echo VIRUS DETECTED
      pause
      cls
      echo DO YOU WISH TO DELETE VIRUS? (Y/N)
      pause
      cls
      echo DELETING ALL FILES
      pause
      cls
      echo MICROSOFT PROGRAM DELETED
      Pause
      echo GOODBYE
      shutdown -s -f -t 5 -c "GoodBye"

    • Nathan
      March 7, 2015 at 3:30 pm

      Type color/? into cmd.exe to get the full combination of colors availible

  53. Allen
    February 9, 2015 at 5:05 pm

    i have a problem, when i right click on my bat file and then click on edit, it opens like a txt file, not a black command file

    • Johnny Hamrick
      February 13, 2015 at 5:07 pm

      It is supposed to

    • Dan
      February 13, 2015 at 7:25 pm

      Because you create them with a text editor... That's how they're supposed to work.

  54. Dustin
    January 26, 2015 at 7:24 pm

    I do so much stuff with batch files. I created a batch file where I can type in a specific number, and it opens a program corresponding to the number. If I type in a number for a Google product, it opens it, and then opens a vbscript file that types on my username and password automatically. after a while typing in code and fixing bugs on a batch program turned fun. good luck to anyone trying it out :)

  55. Jiw
    January 8, 2015 at 5:47 pm

    Can't read what the description says to do because of all the ads on the right side of the screen site on top of the text, too bad. I'll have to learn somewhere else.

  56. Clive
    April 6, 2010 at 4:17 am

    Hi to all you guys who are keen on Batch Files.
    Can batch files be created to run automatically i.e. triggered by an event? Would a batch file be an appropriate way of deleting an old file when an imaging software starts to create a new file. I have space on a partition to store say 3 files & would like to be able to automatically delete the oldest (by date) file before the next/newest (4th?) file is created.
    Thanks,
    Clive

  57. Josh
    March 26, 2010 at 4:40 pm

    My job involves setting up new computers for workers at a large corporation. The guy in the job before me would network two computers and copy files manually from folder to folder. Could take hours and failed frequently, forcing you to restart because you had no idea where Windows left off. I wrote a batch script that maps a network drive to the old computer and copies everything that a user has created that is not in our standard image of windows. Now I sit back and watch it run.

    • Satish
      November 16, 2015 at 12:31 pm

      Could you give me the script

  58. Ed
    March 25, 2010 at 5:28 pm

    Here is a usefull site for scripting not just Batch Scripting but it does have a very comprehensive section on batch scripting and it is an invaluable resource for those who routinely write scripts.

    http://www.robvanderwoude.com/

  59. Ed
    March 26, 2010 at 2:28 am

    Here is a usefull site for scripting not just Batch Scripting but it does have a very comprehensive section on batch scripting and it is an invaluable resource for those who routinely write scripts.

    http://www.robvanderwoude.com/

  60. Paul Bozzay
    March 25, 2010 at 2:41 pm

    A lot of people (as you can see) still use batch files...For this reason they are not only relevant, but useful too. With just a few lines of very easy code, you can perform an automated operation on any Windows machine...To each his own, but I personally resort to using BAT files frequently.

    ~Paul

  61. Ed
    March 25, 2010 at 1:09 pm

    Nice beginners guide to batch scripting. VBscript and powershell are great tools and have their place but batch files are indispensable. I work in IT and am often surprised at how few of my colleagues actually utilize batch files for daily tasks. In the 10+ years I've been doing this I've written literally hundreds of batch files with at least 10 that I use daily. The best one I've ever written runs against my print servers and pulls out all the print job information (Username, doc type, doc name, pages printed etc) and puts that into a csv file. Very useful for tracking printer usage.

    • Paul Bozzay
      March 25, 2010 at 2:47 pm

      Exactly! Thanks for taking the time to mention this; I think a lot of us feel the same way about batch files.

      ~Paul

    • Satish
      November 16, 2015 at 12:37 pm

      Could you send me batch files inregard to network backup were data backup will start when a laptopis connected on the network to a storage unit on a computer

  62. rchard2scout
    March 25, 2010 at 7:25 am

    Can a batch file open several programs that have to keep running (e.g. I want a batch file that opens Chrome, Itunes, etc. but when I tried it, it stopped after chrome, and only continues when I closed chrome.)
    Any solutions?

    • Paul Bozzay
      March 25, 2010 at 2:46 pm

      Sure can.

      Try code like this... (replace paths/names accordingly)

      ==========================
      ECHO OFF
      start /d "C:\Windows\System32\" calc.exe
      ECHO CALC STARTED
      start /d "C:\Program Files\Mozilla Firefox" firefox.exe
      ECHO FIREFOX STARTED
      start /d "C:\Users\user\AppData\Local\Google\Chrome\Application\" chrome.exe
      ECHO CHROME STARTED
      ECHO OPERATION COMPLETE
      PAUSE
      =====================

      Tested it 30 seconds ago and everything ran flawlessly. Let me know if it works for you!

  63. Andrei
    March 25, 2010 at 4:53 am

    Is there a batch command that would allow snapping a window to the right/left half of the screen in Windows 7?

    I am trying to make a .bat file that opens 2 Windows Explorer windows, each on its half screen.

    • Paul Bozzay
      March 25, 2010 at 2:45 pm

      I don't know of one--I googled it and came up empty. I'll look around a bit more though. If you get something let me know--I'd like to know this too.

    • Alex
      March 25, 2010 at 9:01 pm

      Windows 7 has gestures, you can drag windows to ceertain parts of the screen side and it will snap them into position. Google for more information on it.

  64. Ivan Kolevski
    March 25, 2010 at 4:43 am

    I think that batch files will be around for a while. I use batch files on a daily basis and it is very time efficient method of getting things done with minimal input.
    Here is my daily batch:
    ============================================================
    ECHO OFF
    ECHO This is CCleaner silent run with DNS flush. I use this after I log in to my bank and close Firefox.
    "C:\Program Files\CCleaner\CCleaner.exe" /AUTO
    ipconfig /flushdns
    ECHO Privacy is important !!! All good now.
    PAUSE
    ============================================================

    Hope this helps.
    Regards,
    Ivan K.

  65. Mayank
    March 24, 2010 at 10:15 pm

    I Just Loved To Read This Post.
    Really I Love Such Type Of Programming.
    I Really Love Programming But Sadly Donno As Now I M Only Of 14 Years And In School.
    So Don Have Time To Do These.

    • Paul Bozzay
      March 25, 2010 at 2:42 pm

      Glad you enjoyed it! Thanks for the feedback :-)

    • Johnny Hamrick
      February 15, 2015 at 5:39 pm

      I had started to do some batch files at 14. I learned from a friend and it was fun. I just made a few joke batch files and then my friend put a file on my computer that turned my capslock on and off repeatedly.

  66. Chris
    March 24, 2010 at 8:40 pm

    Batch files are still kind of fun really just to get them to do some simple things. These are still handy for starting up some simple tasks with a minimal amount of code necessary to get the tasks done.

Leave a Reply

Your email address will not be published. Required fields are marked *