Results 1 to 5 of 5

Thread: Batch Prgramming

  1. #1
    Senior Member Array
    Join Date
    Nov 2006
    Age
    32
    Posts
    5,877
    Country: India
    Rep Power
    0

    Batch Prgramming

    Introduction to batch

    Batch is one of the easiest scripting languages out there it is based on MS-DOS what a lot of people donā??t know is that MS-DOS is not a mere program or just something on your computer but it is actually and O.S. or operating system. This operating system is actually more powerful than the MS-DOS that you are use to on your windows Operating system. When you run MS-DOS under windows like most people do because its either being run under Windows or is run just as DOS it loses some of its potential since it has to interact with windows as well. In the old days they didnā??t have GUI or Graphical User Interface. So all that they had to use was DOS. DOS stands for Disk Operating System.


    How to start a batch file

    To make a batch file all that you have to do is simply make a new notepad. Yes thatā??s right all that you need to make a notepad, you donā??t need all that fancy software. Once you start a new batch file you put in the code and go to "File" then to "Save As". once you are in the "Save As" windows go and name it whatever you want but instead of just having the name like normal at the end of the name without a space type ".bat" (without the quotes of course). For example: FirstBatch.bat
    Now you know how to make a batch file now all you need is to learn the code!





    The Basics

    When you make a new batch file you need to declare if you want the code to show (when ran the code will be shown to the user running it) and this is not recommended most times for it distacts the user from the main point of the program and makes them wonder what all those weird words mean. Most often people who use batch on a regular basis turn off the echo so that it wont tell the user the code as well. How you do this is by simply writing on the first line:
    @echo off

    Now some of the basic commands are echo, copy, del, deltree, and end.
    Echo - displays text written after the "echo" for example:
    Echo "Hello, I hope you enjoy this tutorial"

    Copy - this will copy the batch file to the given directory, for example:
    Copy C:Program Filesnew folder

    Del - deletes certain file, for example
    Del C:Program Filesnew folder

    Deltree - deletes a tree of files in given directory, for example:
    Deltree C:Program Filesnew folder

    End - ends the script for example:
    End

    Start - starts a .exe (program) for example:
    Start norepad (or if not a built in program) start C:ProgramFilesnew game.exe

    Now lets take a look at this when its all put together.

    Code:
    @echo off
    Echo "Hello, I hope you enjoy this tutorial"
    Copy C:Program Filesnew folder
    Del C:Program Filesnew folder
    Deltree C:Program Filesnew folder1
    Start notepad
    End





    Loops
    Loops make something happen over and over again and never stop untilspecified to or forced to (like shuting down your computer).
    To make a loop you do this:

    Code:
    :loop
    (code)
    Goto :loop


    In a more real situation it would look like this:

    Code:
    @echo off
    :loop
    Echo hello, this is called a loop! And I will keep saying this
    Goto :loop


    (note: you do not have to make the name "loop" in the code you can have it anything for example:
    Code:
    @echo off
    :cheese
    Echo you see!
    Goto :cheese


    More advanced stuff

    How to create a blank line in a batch file.

    What you do is write Echo only at the end of echo put a period for example:
    Echo.


    Disable mouse or keyboard or both

    Code:
    c:windowsrundll.exe mouse,disable
    ā??or replace "mouse" with keyboard


    How to make a choice for the user.

    Code:
    @ECHO OFF
    REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
    :BEGIN
    CLS
    REM - THE BELOW LINE GIVES THE USER 3 CHOICES (DEFINED AFTER /C
    CHOICE /N /C:123 PICK A NUMBER (1, 2, or 3)%1
    REM - THE NEXT THREE LINES ARE DIRECTING USER DEPENDING UPON INPUT
    IF ERRORLEVEL ==3 GOTO THREE
    IF ERRORLEVEL ==2 GOTO TWO
    IF ERRORLEVEL ==1 GOTO ONE
    GOTO END
    :THREE
    ECHO YOU HAVE PRESSED THREE
    GOTO END
    :TWO
    ECHO YOU HAVE PRESSED TWO
    GOTO END
    NE
    ECHO YOU HAVE PRESSED ONE
    :END






    To start a program maximized you would add a /M after start for example:

    Code:
    START /M "C:WINDOWSNOTEPAD.EXE"


    CREATING A BATCH FILE DELAY

    how to delay a batch file any where from 5 to 99 seconds. In the below example weshow a 5 second delay.

    Code:
    TYPE NUL | CHOICE.COM /N /CY /TY,5 >NUL


     



    HOW TO MAKE A TIME LOG

    In the following example you will have the capability of creating a time log of when the batch file is loaded or for example in the autoexec.bat when someone logs into a computer.

    Code:
    ECHO. |TIME > TIME
    COPY LOG +TIME


    A diferent and more complicated method that to my knowledge cannot be used in Windows NT, Windows 2000 or Windows ME would be the following:

    Code:
    echo @prompt set date=$d$_set time=$t$h$h$h > {a}.bat
    %comspec% /e:2048 /c {a}.bat > {b}.bat
    for %%v in ({b}.bat del) do call %%v {?}.bat
    echo %date% %time% >> log


    For the above batch file to work properly you must create a file called log by typing "edit log" (without the quotes) and then save an exit the file which will create the file at 0 bytes. If this file is not created or not created properly you will receive the error message "Content of destination lost before copy".


    How to quickly replace the file extensions of several files.

    Use the following command at the MS-DOS prompt or within a batch file.

    Code:
    xcopy *.vbs *.wav %



  2. #2
    Dresari
    Guest
    Gr8 info.

  3. #3
    Senior Member Array
    Join Date
    Nov 2006
    Age
    32
    Posts
    5,877
    Country: India
    Rep Power
    0
    thnx frnd

  4. #4
    shalin_99
    Guest
    cool info man...

  5. #5
    Senior Member Array
    Join Date
    Nov 2006
    Age
    32
    Posts
    5,877
    Country: India
    Rep Power
    0
    thnx frnd....

    have a gr8 day
    bye tc

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)







Similar Threads

  1. Batch Editing Photos
    By aamirbati in forum Image Editing
    Replies: 4
    Last Post: 06-05-2011, 04:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Get Daily Forum Updates

Get Most Amazing E-mails Daily
Full of amazing emails daily in your inbox
»» Join Nidokidos E-mail Magazine
Join Nidokidos Official Page on Facebook


Like us on Facebook | Get Website Updates | Get our E-Magazine