• Batch Mega thread
    55 replies, posted
This is a mega thread devoted to the long gone, but not forgotten BATCH FILES. [b] DO NOT SEND THESE FOLLOWING FILES OVER THE INTERNET OR IN ANY WAY DISTRIBUTE THESE ONLINE I AM NOT RESPONSIBLE FOR ANY PROBLEMS OR ANY OTHER MISS OCCURRENCE THAT HARMS YOUR COMPUTER IN ANY WAY: THESE FOLLOWING TUTORIALS ARE FOR EDUCATIONAL PURPOSES ONLY DO NOT USE BATCH FOR ANYTHING MORE THAN LEARNING AS BATCH FILES DOWNLOADED FROM THE INTERNET MAY HARM YOUR COMPUTER AND OR SOMEONE ELSE'S COMPUTER. FOLLOW THESE TUTORIALS AT YOUR OWN RISK.[/b] [b] NONE OF THESE FILE WILL DAMAGE YOUR COMPUTER THEY HAVE ALL BEEN TESTED ON MY COMPUTER AND IF COPIED AS IS WILL NOT HARM YOUR/OTHERS COMPUTER AGAIN RUN THESE PROGRAMS AT YOUR OWN RISK[/b] from here forward the terms OTHERS will be referred to as the owner/ co-owner of the computer that will run these programs ------ Batch files are very basic. And they are used by many companies today mainly for SVN purposes i have seen batch files in the SDK for Android and other places i cannot remember! They are used to execute windows shell functions. Early versions of Windows would support features like Net Send and other functions to control someones desktop(which i will not go into!) Net Send could be used to make messenger applications but was taken out after Windows XP(for security reasons?). Batch was the first language I have ever learned and it is good for beginners who want to mess around and get instant results(i am not telling you this is a long term thing, just for a couple hours of fun). Functions and variables: functions are used to do minor things like open programs and create documents and such. [b]comments[/b]: Comments can be used to add additional info to the source code of a program. there are many ways but most are not used. -Rem: [code] @echo off echo hello world rem |this is an example| rem |of comments! | [/code] * i drew the lines around the text to make it more distinguishable.* [b]start[/b]: will start another command prompt window if not followed by the path of an executable. i.e. start firefox.exe. will start firefox if you have it installed on your computer. [b]title[/b]: used to change the name of the program in the console window. i.e. title Hello World Variable: you can save data in things called variables for the rest of your program to use. i.e. set /p [b]text[/b] = hello world [b]Note:[/b] set /p is defining that you want to save the text following "=" as a variable. I think there are other ways but this is how i do it. text is the name of the variable that we will use to call the data back later on and the text after the "=" is what will be held in variable "text". how to call it back: you can call the variable back in your program easily: echo %text% [b]Note:[/b]I added the echo so it will display the text inside the variable text. Other forms of variables: there are variables that are hard wired into windows that you can call back such as: %time% which will print the time if you write echo before it. %date% which will print the date if you write echo before it. Tutorials: there are some tutorials on youtube but most are taken down. Why, i dont know. ok so here are some tutorials [b]Hello world.[/b] [code] @echo off echo Hello World! pause [/code] [b]Save this file as HelloWorld.bat[/b] you can change HelloWorld with what ever you like! Explanation: @echo off means it will hide the directory from which the application is saved. i.e. your program WITHOUT the @echo off command should look like this: [img]http://yfrog.com/0qhellowworldcmdp[/img] echo will print a line of text pause will hold the window from closing until the user hits any button. Ok now onto the more "advanced stuff" since it was made for windows it is easy to trigger programs to start. [b]Quick program start[/b] [code] @echo off start firefox.exe exit [/code] Explanation: start by it self will start another window of command prompt. but if you type an executable after it it should open it if it finds it(it will probably return an error like this: [IMG]http://img259.imageshack.us/img259/2882/windowsstartprogramerro.png[/IMG] By [URL=http://profile.imageshack.us/user/toaster468]toaster468[/URL] at 2010-09-15 exit will exit the program after the lines before it have been executed now more advanced: I have made a program a while ago where you type your mood and it will save it to a diary with the time and date stamped. [b]Mood[/b] [code] @echo off title Your Mood echo Type your mood! echo This program saves your mood to a file which you can review later. set /p name=What is your name?: set /p Mood=What Is Your Mood?: echo %date% : %name% feels %Mood% >> Mood.txt [/code] Explanation: Now this may look confusing at first but i will walk you through it. Title is a simple command to change the name of the program i.e.: [IMG]http://img571.imageshack.us/img571/6395/titlecmd.png[/IMG] By [URL=http://profile.imageshack.us/user/toaster468]toaster468[/URL] at 2010-09-15 echo types the following line of text in the window set /p name will set the variable "name" to what ever follows in this case it would be What is your name?: this will print a line of code in this case we specify for command prompt to save this line to Mood.txt [b]Note:[/b] >> means to add to. so we want to add "echo %date% : %name% feels %Mood%" to document "Mood.txt" and if it does not exist it will by default create one on the users desktop. [b]Messenger[/b] [code] @echo off title Messenger %user% echo enter your name echo. echo. set /p user=What is your name? cls echo Press Any Key... pause>nul Goto A :A Cls echo Messenger set /p n=User: set /p m=message: net send %user%: %m% pause Goto A [/code] Explanation: This is actually very simple. This program asks your name. Then asks for a message. then a recipient. after all forms are filled out the program will send the receiver the message via NetSend (which was taken out after Windows XP SP2)which would send the message to the user. Everything you should know up until now except [code] net send %user%: %m% [/code] this is the line that works all the magic. This is the command that will shoot the receiver a message! but sadly Microsoft took it out due to exploits :(. [b]"Timed" echos[/b] [b]!!! NEW !!![/b] This tutorial will teach you how to spread out commands using the ping command [code] @echo off REM timed echoer :A ping 127.0.0.1>NUL echo Blah [/code] EXPLANATION:This will space out the echos so they will appear about every 1 second or so. Since batch has no real timer command this is useful. So you should know evrything until "ping" by now, ping sends a packet of blank info to a host then it will tell you how long it took, the fatsest packet sent, the slowest packet, and the average. This all takes around 1 second or so REMEMBER THIS IS NOT ACCURATE. ok, the ">NUL" means you do not want to display the info that is received when you receive the packets come back. this way only "Blah" is being displayed every second or so. ------ Thanks for reading and i hope i have taught you well! If any of you have a question or feed back feel free to comment and/or PM me! i will be posting new tutorials in the following days so stay tuned! [b] HAPPY PROGRAMMING [/b] ----- end note: if this goes against any polices of Facepunch please do not hesitate to remove this thread.
.sh > .bat I've never had a single use for batch files on windows.
I believe Windows 7 comes with the new Powershell thing, which is going to replace batch?
Too many disclaimers, not enough information on flow control. Where's "if", "exists", "for", "do", and "goto"? Not really sure batch is worthy of a megathread, either. It's not really useful for a whole lot. It's not like the bourne shell or its relatives, which remain practical to use even for some pretty complex tasks.
that is fine but this is for learning purposes only if you read the OP you would know. batch files can be useful as i will show soon with quick google searching. If you know what you are doing it is surprising powerful [editline]02:47PM[/editline] i will be getting to that i basically wanted to get people to acknowledge Batch as a semi powerful easy to use language. my new tutorials coming out soon should show how to use most statements i have stopped using this for a while so i am rusty
I stopped using batch a long time ago, and, frankly, people should just move on the using some other thing like MSYS+MinGW or Powershell. But that's just my opinion. I've used batch quite a bit in several years, but.. There's just too many good alternatives, even for windows.
I use batch files lots, because, [I]get this[/I], not every computer I work on has MSYS/Cygwin/PowerShell/whatever already installed, and if anything, I'd have to write a batch file to automate the installation of those, first. Nothing's wrong with them.
They're good to impress all the dumb kids in school and fool teachers into your presentation being broken, and that's about it.
I honestly can't come up with one good reason to use Batch... Mass file renaming, maybe?
well again guys, this is just the basics maybe a beginner could stumble upon this and maybe learn a thing or two. Since there is no complicated installation and you can do it right from notepad it is a simple solution to beginners not good at installing libraries and such yet, basically what i'm saying is this is intended for beginners mainly but avid programmers could look back and maybe contribute to this. oh and the large amount of warnings and disclaimers are because, Batch, when in the wrong hands could cause major damage to a computer. i mean it has the power to delete stuff. And I will work on a login system to show how to use if statements. Again contribution to this thread would be very helpful maybe a SVN downloader for the more advanced? I havent really work with a lot of stuff like that so that would be very appreciated
It can be useful if you want to do random things pretty easily. Gotta be creative. For example, lets say you are working on a project and you want to automatically backup all the files when you open them. You could write a simple script that would back up all the project files to whatever location you want and then open up the project. Or perhaps you want to open up a number of programs at once for reason, like when you open up your programming IDE you could have it also automatically load a reference webpage. I'm not at all arguing that you can't do this with other means, I'm just saying that it could be useful. I have plenty of hard drive space and I like keeping a record of what I've done each time I work on something, and a simple batch script could easily do that in a few lines. Really, I haven't used batch since I learned about it in some class a few years ago, but I think it has it's uses. Here is a guide to backing up files I just found. [url]http://www.speedguide.net/read_articles.php?id=1547[/url]
[QUOTE=eXeC64;24849060].sh > .bat I've never had a single use for batch files on windows.[/QUOTE] I beg to differ. [code] @echo off nasm -f bin -o bin\loader.o -Isrc\ -Iinc\ src\loader.asm nasm -f bin -o bin\main.o -Isrc\ -Iinc\ src\main.asm copy /b bin\loader.o+bin\main.o floppy.img [/code]
Haven't used batch since I learned how to install python
Thanks for the support guys! Im working on a couple of higher level a game a login example and probably a file editor you would type like del system32 and it would delete it
How does net send work? If i did /users at school, would EVERYONE on the network get the message? And is it only the CMD prompt window that opens up when I run it?
[QUOTE=teeheeV2;24857912]How does net send work? If i did /users at school, would EVERYONE on the network get the message? And is it only the CMD prompt window that opens up when I run it?[/QUOTE] Vulnerability to this is very rare now. I think the messenger service has been turned off by default, which this used. edit:yeah, it's gone - [url]http://en.wikipedia.org/wiki/Messenger_service[/url] But back when I was in high-school (4-5yrs ago), I tested this out, and every computer in the school saw a little popup that said "I'm Rick James, bitch!" I would have thought of a cooler message if I knew it was going to work. You don't have to choose a user-group if I remember correctly. I did "net send * blahblahblah"
[QUOTE=toaster468;24848318][b]THESE FOLLOWING TUTORIALS ARE FOR EDUCATIONAL PURPOSES ONLY [highlight]DO NOT USE BATCH FOR ANYTHING MORE THAN LEARNING AS IT CAN BE MALICIOUS TO YOUR COMPUTER[/highlight] AND OR SOMEONE ELSE'S COMPUTER. FOLLOW THESE TUTORIALS AT YOUR OWN RISK.[/b][/QUOTE] Lol.
[QUOTE=NPerez;24858012]Vulnerability to this is very rare now. I think the messenger service has been turned off by default, which this used. edit:yeah, it's gone - [url]http://en.wikipedia.org/wiki/Messenger_service[/url] But back when I was in high-school (4-5yrs ago), I tested this out, and every computer in the school saw a little popup that said "I'm Rick James, bitch!" I would have thought of a cooler message if I knew it was going to work. You don't have to choose a user-group if I remember correctly. I did "net send * blahblahblah"[/QUOTE] damn Well how would i go about sending a message to everyone then, because that could be fun.
[QUOTE=toaster468;24850910]Batch, when in the wrong hands could cause major damage to a computer. i mean it has the power to delete stuff.[/QUOTE] So can Windows Explorer. So can almost any programming language. I don't think you need huge warnings about batch being especially dangerous. Back in the DOS days I wrote a sophisticated batch menu, using the "choice" command so that people could press different letters to easily launch various programs. It had a main menu with general stuff, and personalized menus for different users (my parents and brothers). I think the .bat file weighed in around 80k at the end. BTW, "@echo off" doesn't "turn off the directory from which the application is". The "echo off" makes it not show each command on the screen before running it, and the "@" prefix is basically a one-line echo suppressor that makes the "echo off" [i]itself[/i] not show up on the screen. (You could also put "@" on every command in the file, instead of using "echo off".)
I just thought of something... [img]http://ahb.me/rZv[/img]
[QUOTE=turb__;24858491]I just thought of something... [img]http://ahb.me/rZv[/img][/QUOTE] Proves that batch to good for nothing.
I remember my days of batch. I used it to do monotonous tasks. I also remember I could make myself a local Admin on the school PC's and then from the change my network user privelages. Those were the days... Wait, what I'm I talking about, Batch is fucking awful.
[QUOTE=Wyzard;24858449]So can Windows Explorer. So can almost any programming language. I don't think you need huge warnings about batch being especially dangerous. Back in the DOS days I wrote a sophisticated batch menu, using the "choice" command so that people could press different letters to easily launch various programs. It had a main menu with general stuff, and personalized menus for different users (my parents and brothers). I think the .bat file weighed in around 80k at the end. BTW, "@echo off" doesn't "turn off the directory from which the application is". The "echo off" makes it not show each command on the screen before running it, and the "@" prefix is basically a one-line echo suppressor that makes the "echo off" [i]itself[/i] not show up on the screen. (You could also put "@" on every command in the file, instead of using "echo off".)[/QUOTE] oh silly me i meant that. [QUOTE=Loli;24863458]I remember my days of batch. I used it to do monotonous tasks. I also remember I could make myself a local Admin on the school PC's and then from the change my network user privelages. Those were the days... Wait, what I'm I talking about, Batch is fucking awful.[/QUOTE] well again this is more of a beginner thing and maybe a others would enjoy it. I know a bit about batch so i felt like passing something down. I am 14 an i started learning this on and off for about 3 yrs. But sadly in my district they are REALLY strict about damaging shit and they disabled CMD but i think you can still make batch files >:D [editline]10:47AM[/editline] if you guys are curios i can post the source code to the messenger it is like literally bare-bones of a program. I've researched it and found that hackers in the late 80's and early 90's used it to communicate relatively without a trace since it is direct from IP to IP
Bhaych sucks.
[QUOTE=toaster468;24863565]if you guys are curios i can post the source code to the messenger it is like literally bare-bones of a program. I've researched it and found that hackers in the late 80's and early 90's used it to communicate relatively without a trace since it is direct from IP to IP[/QUOTE] If you had done some more research, you would know that communicating directly from IP to IP leaves a LOT of trace, especially if you don't clean your routes. It's most likely the WORST way to communicate safely. [editline]07:47PM[/editline] Okay, may be safely, but not securely and definitely not without a trace :)
[QUOTE=toaster468;24863565]I am 14 an i started learning this on and off for about 3 yrs.[/QUOTE] If it takes you three years to learn to write batch scripts, maybe you should consider another hobby? [editline]10:58PM[/editline] [QUOTE=Ayra;24864778]If you had done some more research, you would know that communicating directly from IP to IP leaves a LOT of trace, especially if you don't clean your routes. It's most likely the WORST way to communicate safely. [editline]07:47PM[/editline] Okay, may be safely, but not securely and definitely not without a trace :)[/QUOTE] What are you on about, p2p conversations leave absolutely no trace unless the network is being monitored or files are being saved - in which case everything leaves traces anyway.
[QUOTE=Ayra;24864778]If you had done some more research, you would know that communicating directly from IP to IP leaves a LOT of trace, especially if you don't clean your routes. It's most likely the WORST way to communicate safely. [editline]07:47PM[/editline] Okay, may be safely, but not securely and definitely not without a trace :)[/QUOTE] sorry im not really a network specialist. I was kind of going out on a limb. ill edit [editline]12:00PM[/editline] [QUOTE=esalaka;24864908]If it takes you three years to learn to write batch scripts, maybe you should consider another hobby? [editline]10:58PM[/editline] What are you on about, p2p conversations leave absolutely no trace unless the network is being monitored or files are being saved - in which case everything leaves traces anyway.[/QUOTE] [quote]i started learning this on and off for about 3 yrs[/quote] maybe if you read my post you would know i havent spent 3 yrs actually learning it. I maybe collectively 2-3 weeks
Even 2-3 weeks is bad. You can learn everything you need about batch in 30 minutes. Batch is still a pile of crap.
i know i was going to edit that as an extreme over statement. [editline]12:35PM[/editline] whatever i guess i will close this thread [editline]12:35PM[/editline] moderators please lock this
Batch threads never end well here here, mostly because a lot of the people that use it just play stupid pranks. You're kind of new, so if you want the thread locked you should PM this section's moderator.
Sorry, you need to Log In to post a reply to this thread.