Jump to content

Recommended Posts

Posted

Welcome to the ultimate guide of batch scripting..

Take a look here.. :D


Index

  • Introduction
     
  • What is Batch?
     
  • A History Lesson
     
  • Requirements
     
  • "Hello World"
     
  • FAQ

 

 

Introduction

 

Ever wanted to know everything about batch? I don't mean the basics, I mean EVERYTHING. Well, you have come to the right place! This thread will leave you stuffed with information. By the end of this, your brain will be overflowing with knowledge. :D

 

What is Batch?

 

Well, Batch is a scripting language. Using Batch, you write a batch file, a compiled text file containing commands that will run in order. The name "Batch" was given to this language because a batch file contains a bundle or batch of commands. Batch files were made to finish tasks in a shorter period of time. Batch files also keep your operating system working. In every windows operating system, there is a least one batch file that is crucial to the operation of Windows.

 

A History Lesson

 

As the Windows OS evolved, so did the use of batch files. Long ago, in the early OS versions, batch files were extremely crucial. Early versions of Windows had batch files that actually made the OS start up properly. Over time, batch files became less useful. Windows could sustain most of its frame without the help of batch files. But in a couple of years, batch files became a source of entertainment. How? Well, some people saw the advantages to batch and its endless possibilities. Soon after that, a new era was born. People started making batch games, applications, and even found ways to create simple antiviruses with them. Batch files are still a popular success today. Without those brilliant minds, I wouldn't be writing this guide.

 

Requirements

 

So, most of you may know that all languages have requirements. Usually some special program. For example, C++ requires an IDE and a Compiler to work. So for Batch, is it the same? No. Not at all. All you need is:

Notepad

 

That's it! The only program you need is Notepad. If you don't know yet, notepad is already on your PC. Can't find it ??? Just go to Start Menu > All Programs > Accessories > Notepad. Now... are you ready to write a batch file? :)


"Hello World"

 

Ok, are you ready to write your first batch file? :P Let's get going! First off, open up Notepad.

 

The first line of code we are going to learn is @echo off. Now what does this line do? Well, it stops your batch file from showing file paths. It makes your program look professional. Just make sure you have this in the first line of notepad.

 

So, your notepad should have this in it:

@echo off

 

Now, have you ever wanted to make your program say something? Well if you do, you have to use the echo command. If I wanted my program to say "Hello World!”… I would type this on the second line of notepad:

echo Hello World!

 

So, now your notepad should have this in it:

@echo off
echo Hello World!

 

Let's just say this is our program. Nothing else. If we saved it (you will learn how to later) and ran it, it would pop up then close in less than a second. Why?!  Well, you forgot to tell the program to Pause! What, did you honestly expect it to pause by itself?  So, how do you make it pause? Well, you just put the command pause on the next line. So your notepad should look like this now:

@echo off
echo Hello World!
pause

 

So what actually happens when the pause command is processed during the run? Well, your batch file will pause and a message will appear. Your batch file will say "Press any key to Continue." Then when you press a key, it will move on to the next line of code. If there is no code left, the batch file will close. This may be a bit confusing, but let's run it and you will understand this.

 

So how do I run my program? Well, first you have to save it. Wait. I know what you’re thinking. You just going to go save it as a text document and then just open it. Yes, that is perfectly... WRONG! You don't save it as a text file. You must save it as a batch file! To do this, follow these three simple steps.

 

Step 1: Go to File > Save as

 

Step 2: Name your file but at the end of the name, insert ".bat" or your batch file will not work at all. For example, I can name it "My Program.bat" and that would work.

 

Step 3: For the "Save as Type" select "All Files" not "Text Files." (This is VERY important. If you don't do this, it will be saved as a text document.)

 

There, you have just saved your batch file! Now it's time to run it. Go open the file you just saved. If it does not open, right click the file and select "Run as Administrator." Once it is open, it should look like this:

JPWyN.png

 

First of all, Well Done! You have just made your first batch file! Now, do you see what the Pause command did? It made the batch file say "Press any key to continue..." Then you pressed a key, and it moved on to the next line of code, which is nothing, so it closed.


FAQ

 

How do I Edit my Batch File Again?

 

Just right click your batch file and click "Edit." It will then open up in notepad. Make your changes and then go to File > Save. Then close notepad and run your batch file again. All your changes should come into action.

 

My Batch File Won’t Run! HELP?!

 

Make sure you are on an administrator account. If it is still not running, right click your batch file and click "Run as Administrator." The batch file should run. If it does run but it just closes automatically, then there is an error in the source code you wrote. Go back and check that again.

 

Credits:Me

Posted

Really Amazing guide,+1 for your job ITS JUST AMAZING

+1 Rep for a guide that shows you have to create an hello world application? Bah..no

 

Thanks for sharing but it's totally for starters.

Guest Elfocrash
Posted

Really Amazing guide,+1 for your job ITS JUST AMAZING

karma fixed.makin a report for your karma abuses.

Guest Elfocrash
Posted

I found it really cool & he made a lot of job to make this guide.

We have +1 to reward people for their job.

yeah ofc.but if it is THEIR job and if it is something unique or saves money for us like raule and psomas' shares or irat shares.not a thing you can just google and get 1million results

Guest Elfocrash
Posted

Let me google that for you

 

About 2,790,000 results (0.27 seconds)

 

yeah so unique

 

Who cares if is it in mxc as long as it is the most common thing and completely useless?

Posted

1: Theres no way you could have written this yourself with your English level

2: Ultimate guide? -____________- going over 'echo' isn't really that advanced or helpful in any way

3: Maybe you should know what you're doing first before 'teaching' it to other people

Posted

It is a very good guide but I have to agree with Elfocrash. It does not deserve karma for the reason, that a tutorial like that can be found easilly on the internet.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...