Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Please excuse my inexpertise. I don't have much experience with the command line.

From my searches, the main reason for CMD use(*) is automation. I haven't, though, found concrete cases. Most examples are either contrived examples or simple cases where automation is not really needed.

Hence my question - What are examples of actions that CMD and batch files are used for in the real world? (And as below - aside from personal preference and where there is no GUI.) I'm not looking for the script itself, just its goal.

*Aside from personal preference, or cases where a GUI is not available.

share|improve this question
I've tried my best to answer your question but it is such a broad question that it will most likely be closed out as Too Broad. I would suggest asking a more precise question as it stands it's very broad –  50-3 Dec 26 '13 at 20:01
Why use C# when there's Java, Batch, C, F, R, etc.? Batch allows you to use existing CMD utilities, instead of wasting your time reinventing the wheel. –  techie007 Dec 26 '13 at 20:23
@techie007 C# was a minor side point. (Edited out now because I see it was interpreted to be a question of batch et al. vs C#.) My question is what automated actions are done in the real world in any language. (Excluding those that would warrant a dedicated application, of course.) –  ispiro Dec 26 '13 at 20:40
To me it seems you're asking why someone would batch more than one program together to accomplish a task instead of writing a brand new application every time just for that task. Time and money for two. ;) –  techie007 Dec 26 '13 at 21:10
add comment

closed as primarily opinion-based by gronostaj, techie007, Moses, Heptite, tapped-out Dec 31 '13 at 16:01

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 1 down vote accepted

Batch files have the same benefit as any other scripting tool, they make doing repetitive (sometimes complex, sometimes boring) tasks simple.

I wrote a very simple batch script a few months ago, because I wanted a set of commands to run every evening at 6 PM. So, I created this script which uses mercurial commands to check for changes (the owner of a site I maintain adds and removes stuff with FTP). Then commits any changes, and pushes them to the origin (my server).

hg addremove
hg commit -m "Daily update from Prod"
hg push

Then I setup a scheduled task to run this script daily. This happens to be the first batch script I've written in years, however, due to me moving to Mac at my latest job where I'm doing development.

However, I use shell scripts (same type of thing on a different OS) daily. The one I use most ensures that I have a network drive mounted, logs me into our source code repository (prompting for a password, of course) and fires of the build script. All in all, it would take me 3 minutes to enter the commands to do this myself, but when I did, I regularly forgot to check that my drive was mounted (mapped), and this caused a 10 to 20 minute delay... The script doesn't forget.

I used to be a system administrator for a community college and used batch scripts all the time, mostly, as you mentioned, for automation. When I started there, we had to visit each machine to manually update the antivirus and run a scan. I created a batch script that would copy the update from a specific location on our network, install it, and start a scan. Then at each machine in a group, throw my floppy disk in the drive, hit Window-R (to open the run dialog) and type a:\up.bat... After I got a few started, I'd kick back and read until they were finished.

I created another script to get new machines (or repurposed old machines) up and running with our standard setup before we bought imaging software. What was previously a tedious process of insert this disc, double click some stuff, click next a few times, wait..., click next some more, switch discs, do the same thing... Turned into insert disc, insert floppy... run command. switch discs when prompted... When the network was more reliable, that was changed to just inserting the floppy and running the command, it downloaded the install files from a network drive for me.

share|improve this answer
Thanks. This is the type of answer I'm looking for. –  ispiro Dec 26 '13 at 21:51
add comment

CMD is just a little power house available on all windows PC's. net user {samid} /domain can quickly tell me most stats I want to know about a domain account and dsquery user -samid {samid}|dsget user -memberof -expand|dsget group -samid covers the rest by recursively looking up group memberships for a domain account.

I can quickly lookup all mapped network locations on a PC: for /f "tokens=3" %f in ('net use ^|findstr \\') do echo %f

Or batches can be used for doing jobs where compiling is impractical

@echo off 
echo This script will close Internet explorer then clear out your temp files
taskkill /f /im iexplore.exe
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
"C:\Program Files\Internet Explorer\iexplore.exe"

This was a quick and dirty batch file that I put together to clear IE temp files. It's easier to drop a bat file onto someone desktop then trying to explain how to clear out there temp files.

Lastly because I can go on all day about the benefits and usefulness of CMD it taught me so much about how scripting works and how the computer interprets commands. It wasn't until I learnt CMD/Batch that I really got interested in Scripting and Programming.


Just a concrete example of CMD being more effective then C# (Hello World!)


public class Hello1
   public static void Main()
      System.Console.WriteLine("Hello, World!");


echo Hello, World!


@echo Hello, World!


@echo off
echo Hello, World!

CMD and Batch has a lot less overhead when it comes to simple tasks.

share|improve this answer
Couldn't that be achieved by mmc.exe? –  ispiro Dec 26 '13 at 19:48
@ispiro that would imply there is only 1 way of achieving any given task. I can assure you though dsquery user -samid {samid}|dsget user -memberof -expand|dsget group -samid takes 2-3 mins to process ~100 memberships if I did it via mmc.exe it might take me 30-40 mins –  50-3 Dec 26 '13 at 20:08
Your answer to my question is: Looking up domain accounts info / network locations / clearing temp files of a running application. (The part about CMD vs C# is not my question. I just mentioned what I did to clarify myself.) Thanks. –  ispiro Dec 26 '13 at 20:22
@ispiro I just mentioned it as a reference to show that cmd is low overhead. Everything achievable from cmd can be done in the GUI and vise virsa. The reason I use cmd heavily is it all there and not in 100 different apps and snap ins. It's all up to the user and how they want to use a computer. –  50-3 Dec 26 '13 at 20:53
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.