Introduction: Use Batch to Print a Directory Tree of a Target Computer
Ok, so in this Instructable I will be telling you how to make and use a program (using batch) that will make a text file containing a directory tree of a computer of your choice. For the program to work you have to have physical access to the target computer.
What is a directory tree? And Why is it useful?
Well, a tree is like a spider diagram of all the files and folders in a directory, giving you the information to work out the exact location and directory string of any file in the C:/ drive of a computer. The files will not be able to be opened from this program, but you will be able to see there names and types. The information can then be used for you to go away and make a 'worm' to find and retrieve the desired file.
I'll start by showing you the basics of the batch program and then continue to give options to where you can take it further. I personally have this program on a spare 52MB USB that I got free on a University open day. I use an .inf file to start the program upon recognition of the USB, then the program (which I converted to a .exe) runs as a ghost program, creating the text file, saves it on the USB directory, and then you're done! And it only takes a few seconds!
Disclaimer - I am not responsible for the use of this information, any laws or computers you break is your own doing. I am merely supplying this information for researching purposes.
Think you're ready? Then let's go -->
Step 1: This Tree Is Anything But Leafy...
It took me a long time to work out how to do this, and as far as I know there isn't anything on the Internet that tells you how, but there was one vital thing I was missing in all my previous attempts, which I will explain later.
So, the code. If you've stumbled upon this Instructable I assume you've made batch programs before, and some of the concepts here aren't for beginners. Never the less I will explain the code as best I can. I will also assume that you know how to make and save a batch file.
echo tree /a /f >%USB%\echotree.cmd
Yes it really is that simple...
Step 2: Mother Nature Makes the Trees? Try TheKnight!
So the code from the previous page:
This is a standard option for the majority of batch files, it stops every piece of code being printed as it occurs.
This bit is crucial so not to leave traces on the target computer. Because Command Prompt was opened by a batch on a USB, the directory that it starts in is that of the USBs. By saving the value current directory, %CD%, as the name 'USB', we can use the USBs directoy to save all the files too.
This then changes the directory to that of the C:\ drive. This is an optional change. If you want to target a different drive, for example if the target computer user has an external hard drive, then this can be changed to any drive you want.
echo tree /a /f >%USB%\echotree.cmd
This is the key piece of information I was missing for ages. Even to this day i'm not quite sure what goes on here, and if anyone knows for sure why it works i'd rather like to know, but I tried it and it works! This prints the code 'tree /a /f' and saves it to a .cmd file, which is then saved on the USB stick as 'echotree.cmd' (Echotree was what I decided to call the program).
The /a part of the string means that the tree will be printed in ASCII, which is required for display in a text file. The /f part means that it will print the names of the files in the directories.
This then converts the .cmd file to a .txt file so we can read it. Same goes here, if anyone knows why this works as opposed to typing 'tree /a /f >results.txt', I would like to know!
This terminates the program
Step 3: Where Do We Go? Nobody Knows...
So where do you go from here? Well I was influenced heavily from this Instructable by Crazy Leprecaun, and am a great fan of his 'ibles.
I used his information on .inf files to build my own and run the program from a USB.
Also you can convert the file into a .exe. I find this to have a little more of a professional touch to it, as you can give icons, run as ghost applications, and hide the containing code. I use this one, but there are many more out there.
I also built a batch (now .exe) of a RESET program and ran it as a subshell (The first hyperlink for more information) which resets the entire USB to start again! I.e. gets rid of the results from the most recent tree.
If you're crazy lazy then below is a zip folder containing the files on my USB, if you unpack it and throw it on a USB then you should be good to go! Make sure you check all downloads with adequate anti-virus software! I'm not resposibe for any virus' you may contract.
Hope this was insiteful! Please Rate!