Arcade Prehacks

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Senior Member
    Join Date
    Sep 2010
    Location
    Programming something else...
    Posts
    894

    How To Write Programs In Batch

    Alright, all my applications I have created up to this far are at least decent. So now I am writing a tutorial for it. Batch processing is a very easy language to learn and use. And when I say very easy, I mean, really, really easy.
    Now then. Let's start with some of the most common commands you will be using.
    Code:
    cls:  Clears the screen of the .bat
    pause:  Waits for the user to press a key
    echo:  Displays a message on the screen
    echo.: creates a blank line (Like the return button)
    goto:  Goes back to a label you make in the processing.  Good for looping
    @:  When placed in front of any operation, it will hide or cloak the operation to make it look neat
    start:  Runs a program or launches a URL.
    That should be good for writing a basic batch file.

    Now, let's create a batch, shall we?

    The first thing you wanna do is open notepad++. You can use notepad, but notepad++ just makes it neater and points out errors for you and changes the color of commands and, ahh forget it, just use notepad++ ok?

    Code:
    Now, let's type the first line.  The first line you should ALWAYS write in ANY batch file is @echo off.  @echo off cloaks all the operations in the batch files to make it look much much neater.
    Now, let's type some messages eh?
    Hit enter to go to the next line, and type 'echo' without quotes of course.  After echo, type any message you want, let's use'Hello'.
    Now hit enter and type 'echo.' to make a new line on the .bat.  This is not necessary, but makes it neater once again.
    Now type pause.  This will make the batch say 'Hello' and then prompt for user input.
    Now, just hit enter and type 'exit' and save as a batch file.
    Then open and test it.
    That is a simple batch file.
    Now for something more fun and more advanced!

    I am going to show you how to make a loop.
    Code:
    Make a new document.
    Once again, type 'echo off'
    Type :A  (This is a label)
    Now type 'echo The Infinite Loop!'  Or any other message you want displayed.
    Hit enter and type goto :A
    Then save as a .bat and test.
    Now you know how to make a loop. Now let's move on to some more advanced commands that expand the possibilities of batch.

    Code:
    ping -n 5 localhost > NUL  (This is a wait command, change the number to any amount of seconds you want the program to wait before executing it's next command)
    pause > NUL  (Does the same thing as pause, just doesn't show the message 'Press any key to continue')
    if (These commands are hard to work with, but widely expand the possibilities of batch.
    choice  (Gives Y/N choices)
    These are some more advanced commands.
    Now let's put them to use.

    Code:
    Open a new one, @echo off.  That should be standard to you now.
    Let's type echo Hello again.
    Enter, now type ping -n 3 localhost > NUL
    Enter, type echo Would you like to run this program?
    Enter, choice
    Enter, cls
    Enter, Application Loading...
    Enter, ping -n 10 localhost > NUL  (Waits ten seconds and looks like it is loading)
    Enter, echo.
    Enter, echo Thanks for trying this program!
    Enter, echo.
    Enter, echo Press space to close this window
    Enter, pause > NUL  (They can really press anything, but this looks more professional)
    Now you get how to construct basic batch files!

    Now let's learn how to make MsgBoxs appear on screen. This one is still pretty simple, but you're gonna learn a little bit of VB!

    Code:
    Open a new file, @echo off
    Enter, echo Hey once more!
    echo.
    echo So are you ready for this?
    choice
    cls
    echo OK, now please press OK to run the program
    ping -n 2 localhost > NUL
    ***Tutorial Changes Here***
    Code:
    Leave what you are doing open, and open another window.
    Type '
    x=msgbox ("text" ,0, "title")
    Replace text with Do you want to run this program?  (Keep the quotes in)
    Replace title with 'Run'.  (Keep the quotes in)
    The zero represents the kind of MsgBox that appears.  Here is a list of what can be put in.
    Option Boxes
    0:  OK only box
    1:  OK and Cancel
    2:  Abort, Ignore, Retry
    3:  Yes, No, Cancel
    4:  Yes, No
    5:  Retry, Cancel
    OK only info boxes
    16:  Critical Error
    32:  Question
    48:  Exclamation
    64:  Information
    Change the 0 to a 4.
    Save as support.vbs (Visual Basic Script File)
    ***Tutorial back to batch here***

    Type @start support.vbs (This will make the message box you just programmed pop-up)
    Type pause
    exit
    Save as a .bat
    And Done!
    Now you know how to create some medium level batch files!

    But, you may be wondering, how do I turn my batch file into an exe?
    I'll tell you. You download the attachment, it is a free legal batch to exe converter that works GREAT!
    Code:
    Now open the Bat to Exe and browse for the batch file we just made that includes messages.  Locate it, then put it in.
    Then change the output name to whatever you want.exe
    MAKE SURE THAT TEMPORARY DIRECTORY IS SELECTED AS THE DIRECTORY OR IT WILL NOT WORK!
    Click the Include tab, and add the support.vbs file.
    Then if you want, you can make a program icon and set it as that, but you don't have to.
    Now just press compile and it will convert the two files into an .exe!
    Now it should work!
    Please note that AV programs DO NOT like home made programs

    And that should be it! I can answer any other questions here!
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Jul 2010
    Location
    The Netherlands
    Posts
    1,862

    Re: How To Write Programs In Batch

    Maybe you should put the code in code tags.
    It makes it easier to read.
    I've been here before.

  3. #3
    Senior Member
    Join Date
    Jul 2010
    Posts
    735

    Re: How To Write Programs In Batch

    Why do you always publicly admit to being new at things and not knowing a lot about them, then you go and make tutorials for it?

  4. #4
    Senior Member
    Join Date
    Jul 2010
    Location
    The Netherlands
    Posts
    1,862

    Re: How To Write Programs In Batch

    He probably wanted to give it a try.
    Good job Ace. Looks good
    I've been here before.

  5. #5
    Senior Member
    Join Date
    Sep 2010
    Location
    Programming something else...
    Posts
    894

    Re: How To Write Programs In Batch

    Quote Originally Posted by Magicman
    Why do you always publicly admit to being new at things and not knowing a lot about them, then you go and make tutorials for it?
    Because I actually know what I am doing in this one. And I also don't wanna go around saying 'Oh, I'm a pro' when I'm not.
    Quote Originally Posted by Sublimity
    He probably wanted to give it a try.
    Good job Ace. Looks good
    Thanks!

  6. #6
    RedFaceofAwesomeness's Avatar
    Join Date
    Dec 2010
    Location
    New York
    Posts
    621

    Re: How To Write Programs In Batch

    Could doing this risk your computer.

  7. #7
    Senior Member
    Join Date
    Sep 2010
    Location
    Programming something else...
    Posts
    894

    Re: How To Write Programs In Batch

    Only if you are dumb enough to write a program like the hard drive wipe, or memory format and then LAUNCH it. But if you are that dumb, you deserve to have your hard drive wiped.
    But if you convert a hard drive wipe batch to an exe, there is no way your computer will let you run it.

  8. #8
    RedFaceofAwesomeness's Avatar
    Join Date
    Dec 2010
    Location
    New York
    Posts
    621

    Re: How To Write Programs In Batch

    Well I was just saying.
    I heard they were dangerous.

  9. #9
    Senior Member
    Join Date
    Sep 2010
    Location
    Programming something else...
    Posts
    894

    Re: How To Write Programs In Batch

    They can be, but only if you program them TO BE dangerous. Making something like what is up there cannot hurt your computer. It is an easy, fun, and dynamic language to work with. Try it out bro.

  10. #10
    RedFaceofAwesomeness's Avatar
    Join Date
    Dec 2010
    Location
    New York
    Posts
    621

    Re: How To Write Programs In Batch

    I have and It works.
    Thanks anyway.

Page 1 of 2 12 LastLast

Posting Permissions

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