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!