Tuesday, March 29, 2011

Adding Quotes to Lines in Text

Let's discuss quite a simple task today. Imagine: you need to change each line in a text file by adding quotes to it. I mean you want to get from list like listitem1, listitem2, listitem3... list like "listitem1", "listitem2", "listitem3". This is quite a simple task, and the script solution looks like this:
@echo off
for /f "usebackq tokens=*" %%c in ("about.txt") do (
echo "%%c",>> about1.txt
)

As far as you can see, it's not difficult to write this script with help of our award-winning batch files editor. Hope you'll find this small example useful.

Friday, March 25, 2011

How to Register Many DLLs/OCXs at Once

It is sometimes necessary to register a COM or ActiveX library. As far as you know, it is easy to perform it with help of Regsvr32 utility by Microsoft. But it is hard to type the name of library to be registered each time when you need to register a lot of them. It's really easier to copy all needful files to a single folder and then register them all with help of really simple script:
for %%i in (c:\DLL\ActiveX\*.dll) do regsvr32 %%i
for %%i in (c:\DLL\ActiveX\*.ocx) do regsvr32 %%i
Please note that you can register even remote files
for %%i in (\\192.168.102.184\DLL\*.dll) do regsvr32 %%i
for %%i in (\\192.168.102.184\DLL\*.ocx) do regsvr32 %%i
Hope you'll find this example useful.

Wednesday, March 23, 2011

Dr.Batcher 2.1.4 Is Released

We are glad to introduce an update for our award-winning batch files editor. In this version you will find the following new features:
  • tab-bar with bookmarks in professional mode;
  • support for declining use of unnecessary list parameters in simple mode;
  • support for viewing latest post from 'World of Batch Files' blog on start;
  • 10 new examples;
  • improved compatibility with Windows 7 64-bit;
  • lots of bugfixes.
Hope you'll enjoy this update.

Friday, March 18, 2011

Hiding Password Input in Batch Files

It is sometimes necessary to ask user a password from a batch script. Unfortunately, batch files don't allow you to hide input with "*"s, like ordinary password forms in Windows or Web. Of course, the easiest way is to leave everything as it is, but much better is to hide the password without showing anything. The following batch script shows you how to perform such hiding of characters:
@echo off
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>in.com
set /p password=Enter password:
for /f "tokens=*" %%i in ('in.com') do set "password=%%i"
del in.com
echo.
echo The Password is:"%password%"
You can easily change this batch file with help of our award-winning tool Dr.Batcher. Hope you'll find both of them (script and tool) useful.

Monday, March 14, 2011

Ping List of IPs

It's pretty easy to ping a single IP with help of standard 'ping' command. But sometimes it's necessary to ping several addresses at once. Unfortunately, ping's syntax doesn't allow you passing the prepared text file as an input parameter to check all IPs listed in it. What to do? Just download Dr.Batcher and start writing really useful script in it.
The script is quite simple. If looks like this:
@echo off
for /f %%i in (test.txt) do ping -n 1 %%i
You can easily enhance it with writing the results of pinging to the text file (log). Input TXT file (test.txt here) should just contain the list of addresses to be pinged, one per line.

Tuesday, March 8, 2011

How to Avoid Using Gotos

Batch files make you to use 'goto', an obsolete and quite unpleasant construction that makes your code unreadable. This is a common opinion, but I want to discuss the way to avoid 'goto' commands in your batch scripts.
The traditional way to build batch files since the early days of MS-DOS looks like this:
if condition goto :THEN
rem Something like ‘else’
rem ...
goto IF_END
:THEN
rem Something like ‘then’
rem ...
:IF_END
This is really different from the way of writing 'if' statements in C, Pascal, Java and even VBScript. Look at the modern batch script below. Does it look like C or Java code?
if
condition (
rem ‘then’
rem ...
) else (
rem ‘else’
rem ...
)

It's not hard to use these constructions, simply don't forget to add 'setlocal enabledelayedexpansion' (without commas).

Friday, March 4, 2011

Batch File to Open URL

Today I am glad to introduce this short post that should give the answer to a short user's question. The question was "How to open URL via batch file?".
Fortunately, to open URL with the default system browser, you should do almost nothing. The sequence of action looks like this:
1) Start Dr.Batcher and create a new batch script;
2) Switch to Simple mode;
3) Add a new command named "Start a Separate Command Promt" (START);
4) Change the value of parameter 'Command or program to start" to your URL surrounded with commas (for example, "http://www.drbatcher.com");
5) Set other needful parameters;
6) Add more URLs if necessary;
7) Enjoy!

Wednesday, March 2, 2011

Remove All Files Except Today's One with Help of Batch Files


Task to be discussed today is "How to remove all files from the specified folder except the file with today's name?". This is not a very common task, but it is useful for making different backup batch scripts. And this task is simple, as far as you can see. The code below shows how to delete all files in the current folder except the file which name contains today's date.
@echo off
attrib +r *%date%*
del /q *.* 1>nul 2>&1
attrib -r *%date%*
Hope you'll find this simple code useful.

Translate