Monday, 16 January 2012

Advanced Batch

This post is continuing from my earlier post Batch Basics.
Thanks goes to Ashyelm for helping create this post,great work :)



Disclaimer:
We take no legal responsibility for damage done to your computer with the use of the commands displayed here.





==Geting Information

To make scripts that work with Windows 7,Windows Vista,Windows XP,Windows
you must know what commands and applets can be used

TIP: Windows Batch wont work with other systems like Luniex,Mac OS,Cloud OS

To gain information on certain parts of your computer you can use these in command line or Powershell
To open command prompt,you can use the command
@echo off
command.com
Saving that in a .bat form from a text editor will save it as a CMD shortcut.

Echo %OS%

This will tell you what the system was built on


Help

This will list all the avaiable built in commands, Some times OEM include more then included with a Windows Os

Systeminfo

This can Give you information about the Computer and Model

Ipconfig

This will list the machinces Internet Protocols
and any virtal ips or vpns that are attached with it (see my vpn guide)


You can also make these comands save the results in text files, some examples:
Ipconfig >C:\Ipconfig.txt
Systeminfo >C:\Systeminfo.txt
Help >C:\Help.txt
Echo %OS% >C:\OS.txt

====== Batch Basics =======

Leave comment in script

REM  COMMENT HERE

Change color command line background

1st DIgit = Background 2ed = Text
Color NUMBERS

0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White

Example color 03

Clear Text

Cls

Set Title for the command line:
Title "Ashyelm Command Line"

Moving in the Command Line:

CD DIRNAME
CD C:\DIRNAME
Eg C:\Users\admin\downloads
or
d:
this will run cmd from d: instead of c:
Move Back
CD..

List files in current Directory

Dir

In other directory
Dir C:\WIndows

Family Tree of a diretory and its sub directorys

Tree


Tree C:\Users\USER1

Folder Operations

Make a directory in current directory
Mkdir "My Scripts"

Make directory else where
Mkdir "C:\Windows\System\AshyelmMETA"

TIP You should use " " Marks because it will make the name allow spaces if you did mkdir lol the
it would give you an error as it thinks you are trying to do more then 1 command

Remove / Delete Directory

WARNING THIS WILL DELETE THE DIRECTORY IT WILL NOT GO TO THE RECYCLYING BIN IT WILL BE
DELETED..yeah,so dont blame us when your stuff/you delete stuff on your friends machine for a "laugh".

Rmdir "NAME"
OR
Rmdir "C:\Name"
Switches
/S
WIll remove all files inside that folder " If you did RMDIR Name it would say that file is not empty and not allow you to remove it"
/Q
Quiet Mode
Wont ask you if you want to remove it and jest does the command

RMDIR "Name" /S /Q

Ren OR rename

Rename File or Directory
Rename "C:\Logs" "LogsForWork"
New name: C:\LogsForWork
Rename all files with certain extentsion in current directory
eg:
Rename "*.txt" "Userlog.log"
Rename ".exe" "trollz.txt"

Rename Files
Rename "Work.xdoc" "WorkforSchool.xdoc"


When renaming you must include the files extentsion unless its a folder

Change a file extentsion
Ren "lolflilm.txt" "lolfillm.log"

Delete file

Delete or Del

Del Mywork.txt

Del C:\Mywork.txt


Delete all files in a certain directory with a certain extension
Del C:\User\User1\Appdata\Local\temp\*.txt
Del %Temp%\*.txt

Switches for del
/P
Prompt for deleting of each file
/F
Force Deleting of read only files
/S
Delete same files from sub directorys


Del %temp%\*.mp3 /P

MOVE Files

Move "LOL.TXT" "C:\"
Notice: You have to actually have the file "LOL.TXT" for that command to work . . .unless just use a file that you already have . . .

Switches
/Y
Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y
Causes prompting to confirm you want to overwrite an existing destination file.

Copy files

Copy "Filename.txt" "C:\"

Switches
/V Verifies that new files are written correctly.
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.

Take ownership


This will take over a file or directory that is not owned by you this is a good way to
protect stuff from other administartors that cant use the takeownership command themselfs
making you only able to edit and delete the data
can only be used by administators

takeown lol.txt /F
takeown C:\Windows /F

Start a certain program

start c:\programs\mozila\firefox.exe

list all runing tasks
tasklist

task kill

WIN 7  / Win Vista
Taskkill Explorer.exe /F
WIn XP
Taskkill Taskkill /F Explorer.exe

Variables
Variables are used to shoren commands
Note: you have to type the "echo" command before each of these variables


Some basic variables are



%USERPROFILE% Will take you to C:\Users\YOUR USER
%USERNAME% Will print the current user loged in echo %username%
%TIME% will show time echo %time%
%DATE% will show date %date%
%OS% will show build
%TMP% will show location appdata temp
%TEMP% ^
%DOMAIN% WIll show logon domain
%RANDOM% Will echo a random number


to set your own

set a=C:\Creds
to use it you would type %a%


Displaying text
Echo is a very powerfull but mis understood command
It can be used for building batch files in batch files
and used to display vairbles

Echo Lol
That would display lol in the command line
Echo %USERNAME%
That would display my username
Echo:
That would leave a break
@Echo off
this would turn off the location the current directory the command line is in

To build files

Echo :1 >Virus.bat
Echo Start Cmd>>Virus.bat
Echo goto :1 >>Virus

This is an example of how you could make batch files make other batch files
 or text or html files

echo would not be included in them files unless you typed echo echo
> makes the file
>> adds to the file