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.

Sunday, November 28, 2010

We're Going to Launch New Site for Dr.Batcher

Mental Works Computing Software is proud of announcing Dr.Batcher's new site under construction. This site will not be just the re-designed old one. We are going to create special new section with tips and articles on batch files. Of course, the design will also be updated. The site will look much better and it'll be easier to navigate on it. Also we plan to create video-tutorials on creating batch files for different purposes with help of Dr.Batcher. Hope you'll be able to enjoy it all in a month or two.

Thursday, November 25, 2010

What Tasks Can One Automate with Help of Batch Files?

We are sometimes asked: "What kind of tasks can I automate through batch files?" Our usual answer is "any kind". Of course, it depends on your needs. Here are some common tasks for IT specialists that can be automated with help of batch files.
Administrator: creating and restoring backups, changing network settings, cleaning junk files, starting and stopping services...
Programmer: making builds, starting applications under certain runtime environment, running different command line-tools with specified set of options...
Beta-tester: running applications with given parameters, running applications under different environments...
Here are just a small amount of examples. For what do you use batch files? Share your experience in comments.

Wednesday, November 10, 2010

How to Start or Stop a Windows Service with Help of Batch Files


Some users ask us how can they start Windows service with help of a batch script. That's why we decided to write a short post on this topic in our team's blog.
First of all it should be mentioned that starting or stopping some Windows services can make your system work strangely. Thus you should work with services really carefully, especially with standard services installed while the installation of the operating system.
Actually, you should know only one command to run or end Windows services. This command is called NET. To run a service you should add to your batch file the following line:
NET START "Service Name"
And to stop a service you have to use this construction:
NET STOP "Service Name"
Of course, you have to use the real name of the service you want to start or stop instead of Service Name.
It's really easy to work with services, as you see. If you have any questions about batch files, feel free to ask us via support@m-w-c-s.com.

Monday, October 25, 2010

Dr.Batcher 2.1 Is Released

Today we're glad to introduce new version of Dr.Batcher. Though there is a lot of different small improvements in it, the main difference between this and previous versions is support for compiling batch files to EXEs. We've tried to make the process of EXE creation as handy as possible, so today you can find a new wizard in Dr.Batcher (choose "Tools" -> "Compile EXE File"). The wizard look like this:


You can find detailed information about the new version of Dr.Batcher here. Hope you'll enjoy it. You are still always welcome to send your suggestions and reports at support@m-w-c-s.com.

Wednesday, October 6, 2010

Creating And Upacking ZIP Archives Using Batch Scripts

Sometimes it's necessary to create archives and extract files from them with help of batch files. For instance, it's useful when you writing scripts for automated backups. There is a number of different console archivers available on market, but still the most famous one is PKZIP (together with unpacker PKUNZIP). This archiver is especially useful for those who still use DOS for some reason.
The following command will help you to compress all files in the current forder:
PKZIP -a -ex -r -P -whs %1 *.*
If you put this line to a text file and save it as 'zip.bat', then you should just call 'zip.bat c:\archive.zip' to compress all files from the current folder to c:\archive.zip.
To extract files from the created archive to the current folder, you have to use the following command:
PKUNZIP -d %1 -o .\
The only parameter passing to this short batch file is the name of ZIP to be extracted.

Translate