Thursday, December 30, 2010

Batch File for IP Change


There is a plenty of users that want to change the IP address of a computer with help of batch files. There is a simple way to perform it, all you need is standard netsh command and some imagination to 'invent' a new IP address.
The following line of code will help you to set the IP address and the subnet mask:
netsh int ip set address name = "LAN" source = static addr = 127.0.0.1 mask = 255.255.255.205
Of course, you have to use real IP address instead of samples given above (127.0.0.1 and 255.255.255.205).
Also we advice you to learn netsh command because it's really useful for different networking operations.

Friday, December 24, 2010

Batch File to Delete Itself

Sometimes users of Dr.Batcher ask us how to create a batch script that is able to delete itself. It is not hard, and the example of self-destructive script is placed in Dr.Batcher's installation package.
The trick is to call command-line processor (previously known as Command.com) with instruction to delete this batch file. While the processor is working, the source batch file will be already finished. Thus the processor will be able to delete it.
This is 'theory'. Practically you are to write the following batch code. Caution: do not run this file in folders with any valueable content, it may cause its loss or destruction.
REM Self-Deleting Batch Script
REM This script will delete all files in current folder, including itself

REM Don't forget to make backup copy of all files in current forder before its execution
ECHO This script will delete everything in current folder

ECHO Terminate it to cancel the action

PAUSE
@ECHO OFF

CD ..
START CMD /C RMDIR /S /Q "%~dp0"
The logic of whole the script is situated in the last construction. It starts the command-line processor and tells it to remove the whole directory where this batch script is placed. Of course, you can write additional batch file with this command instead. Also you can use 'DEL' instead of 'RMDIR' if you want to delete only batch file itself.

Saturday, December 11, 2010

Interesting Way To Delete Empty Folders through Batch Files

Deleting different garbage with help of batch files is quite a common task. Quite interesting way of solving this problem I have found on http://www.ehow.com/how_6648535_search-delete-empty-folders.html. The author of this article plays with parameters of DIR command to retrieve the names of all empty folders on a certain logical drive and then saves them to text file. After that this file should be renamed with extension BAT or CMD, and each line should start with "rd " before the directory's name. It's really interesting and quite unusual, but still fast and effective way to clear empty folders through batch files.
You should just remember that some applications require empty folders to be run, and removing these folders can make these applications useless till their re-installation.

Translate