dosbatch files

dos/batch files

we've already played around in dos a little bit, but haven't even begun to touch on its real power. think of the command-line as a backdoor to your computer. my local community college has their whole network locked down extremely tight; in fact it only takes a few incorrect login attempts on one of the public cafeteria computers before security shows up (i've heard rumors of the feds showing up on at least one occasion). sounds secure enough, right? wrong. for some reason they let you access dos and although it is possible to disable certain dos commands, they don't. all of that security is practically pointless because of dos, and you don't even need to login to a computer to access it.

the first thing you should be familiar with is how to navigate around, so go ahead and open up the command-line console (win+r, type "cmd"). dos has two types of commands: system commands and network commands. to see a list of all the available system commands that you have access to, simply type "help" (pressing enter should go without saying) and a list will be generated with a brief description of each. for a more detailed description of a particular command, as well as its "flags" (which are optional ways to be more precise about what the command is supposed to do) type the command's name followed by a space and then "/?"… dos commands are usually a little different depending which version of windows you're using, and we're going to be focusing on those related to xp as that's the os this book revolves around.

  • cd/chdir changes the current directory. type "cd c:\temp" to go to the temp folder, or just "cd temp" if you're already sitting below that directory. typing "cd" followed by two periods will take you down one directory. navigating to a folder that has spaces in its name can be tricky; first let's create a folder that has spaces.

  • md/mkdir creates a directory. type 'mkdir "c:\temp\i have spaces"' to create a folder. note that you must surround the entire folder path (not the command) within double quotes, otherwise it will create three different directories: i, have, and spaces. you can use the same approach to navigate to a folder with spaces, by surrounding it with double quotes; however, this may not always work. if you are unable to navigate to a folder or file with spaces using double quotes, then you will need to refer to the folder/file by its system name. to find out the system name, use the following command.

  • dir displays the directory contents. type "dir" to display the current directory contents; contents will be listed by their system names. you will notice two directories consisting only of periods: these directories appear within every folder as they are part of the default system.

  • edit creates or edits a file. type 'edit "c:\temp\i have spaces\test.txt"' to create the file test.txt. note that we are once again surrounding the path, not the command, with double quotes. type anything you want in the blue screen, then press "alt" to access the menu, type "f" for file, "a" for save as, then tab down to the "ok" button and press enter. access the menu again to exit. you can edit system files this way as well.

  • color change the text color to make things prettier. type: "color /?" to see a list of flags. type "color e0" to make the background yellow and the text black.

  • title change the title of the dos window. type "title woohoo!" to change the title to woohoo!

  • copy copies one or more files to the specified destination. type "copy /?" to see a list of flags. type 'copy c:\temp\bluescreen.jpg "c:\temp\i have spaces" /b' to make a copy of our image in another directory. note our use of quotes. the "b" flag indicates the file is binary.

  • move moves a file rather than making a copy of it, as well as renames files and directories. type "move /?" to see a list of flags. i don't feel like moving anything.

  • ren/rename renames an existing file. type 'rename "c:\temp\i have spaces\bluescreen.jpg" hahaha.jpg' to rename our image file; note the quotes.

  • tree draws a tree of the folder structure. type "tree c:\temp /f" to display the contents of the temp folder and sub-folders. the "f" flag indicates that you want to see the file names.

  • del/erase deletes one or more files. type 'del "c:\temp\i have spaces\*.*" /q' to delete all files in our folder; note the use of quotes. the "q" flag indicates that we want to delete files quietly; in other words, do not ask me to confirm before deleting. an asterisk is known as a wildcard, which can stand for anything. we are basically saying, delete all files named any-name.any-extension and do it quietly. a question mark can be used in place of an asterisk as an alternative form of wildcard, which replaces single characters with any other character, as opposed to any number of characters.

  • rd/rmdir deletes a directory, or an entire directory tree. type 'rmdir "c:\temp\i have spaces"' so i can stop telling you to note the usage of quotes, because we will no longer have a directory with spaces.

  • format this more or less erases everything on your computer. type…on second thought, don't type anything.

  • print sends a file to your printer, if you have one. type "print /?" for flags and instructions.

  • shutdown shuts down a computer. type "shutdown /?" to see a list of flags. type 'shutdown -f -t 10 -c "you suck"' to shut down your computer in t-minus 10 seconds, force all running applications to close, and display the message "you suck." note the use of quotes. type shutdown f m \\compname /t:10 -c "illegal operation" to shut down another computer on your network remotely,

    another way to interact with other computers over a network would be as follows.

    right-click "my computer" and click "manage"

    in the left pane highlight: computer management (local)

    then right-click it, choose the option to connect to another computer. after you've connected with a computer you can use these options to send messages, shutdown, etc...

    the cool thing about this method is it works on many different wersions of windows.

  • exit exits the command line window. type "exit". if you want to cancel something currently in process that's taking too long, type "ctrl+break".

all this by itself is cool, but seems pretty useless. what is the point of doing things via the command line when you have a nice graphical interface, right? the answer is batch files. a batch file is a file containing dos commands that you can execute to automate certain tasks, or simply to make repetitive tasks less of a hassle. a batch file can even be interactive to an extent. below i will cover a few dos commands commonly used within batch files. to create a batch file, simply open notepad, type your dos commands one line at a time (each command needs to be on a separate line), then save the file with a .bat extension.

  • echo prints a line of text in the window. type "echo hello world" to see the message "hello world." type "echo off" to remove commands from being displayed, or "echo on" to turn them back on. the "@" symbol before a command will suppress the line from being displayed as well.

  • pause will pause execution until a key is pressed to continue. type "pause" to freeze execution.

  • cls clears the screen. type "cls" to clear the screen.

  • schtasks schedules a task or program to automatically run whenever you want. type "schtasks /?" to see a list of flags. type "schtasks /create /sc daily /tn mytask /tr c:\temp\myfile.bat /st 20:00:00" to create a daily task of myfile.bat, named mytask, which will run at 8:00 p.m. every night. you may be prompted for your login password to schedule a task.

  • if/else flow control. type "if exist file.txt (del file.txt) else echo file.txt missing" to check whether a file exists, delete it if it does, and tell you if it doesn't.

  • goto a way to jump around to different blocks of code. define a marker by preceding any word with a colon (:likedis), then you can jump to that marker if you type "goto likedis", which is best used in combination with a conditional. in a way, it is almost identical to a function, the main difference being that when a function is done executing the code picks up where it left off, whereas once the goto statement jumps over code it doesn't ever go back unless you specifically tell it to.

  • for a loop. type 'for %f in (*.jpg *.jpeg) do rename "%f" "pwn3d_%f.????"' to rename every jpg/jpeg file with a prefix of "pwn3d_" in the current directory. one last time, note the quotes. one percent sign should precede variables (in this case, f) when used in the command line, but two percent signs should precede variables when used in a batch file. the question mark is another form of wildcard, replacing one specific character rather than any number of them; in this example, the question marks are replaced with whatever chars are available from the file name it is replacing (so each file keeps its original extension).

    to send 1000 messages to another workgroup on a network, type for /l %i in (1,1,1000) do net send/domain:workgroup "ur pwn3d"

i haven't covered anywhere near all of the commands available, as i am just giving you the general idea of how this thing works; however, if you'd like to see a complete list with more elaborate explanations, uses of each command, and examples provided, just visit and search for "command line reference."

with the use of batch files and the task manager you can schedule random messages to start printing. by putting a batch file in the startup folder, you can have a computer shut down every time it is booted up, or you could create a shortcut to the batch file and create a key-combination to trigger it. you can automate just about any common task in a nice little compact file for annoyance galore, or i suppose you could actually do something useful with this information. whatever the case, the possibilities are slowly becoming endless.

imagine having a shortcut which looks like it opens ie, and the target actually opens a batch file which does something and then opens ie before quiting. you've got a hidden process.


it is worth noting how dos handles space. when navigating to a folder which contains spaces in dos, you don't need to use quotes. for example, typing: c:\program files\internet explorer\iexplore will open internet explorer. but how does windows know you're not really trying to call c:\program.exe w/ the parameter "files\internet explorer\etc."? the answer it that windows doesn't know, instead it guesses by trying the following in order:


c:\program files\internet.exe

c:\program files\internet explorer\iexplore.exe

so technically, you could name a program "internet.exe" and put it in your "program files" folder, and it would run every time windows calls something in the ie folder that doesn't have quotes around the path.

microsoft does know about it, and therefore you might get warning boxes informing you of the problem. that warning can be disabled in the registry, and there are quite a few paths in the registry without quotes.

i think you get my point.

Tapeworm - 1337 Hax or Handbook
Tapeworm - 1337 Hax or Handbook
Year: 2005
Pages: 74 © 2008-2017.
If you may any questions please contact us: