Freeware Windows command-line,
(DOS style), utilities

By John Fitzgibbon
Last updated: Sunday, April 16, 2006, 06:48 PM PST






Introduction
Here are some small command-line utilities I've written, mainly for use in Windows batch files. Feel free to download any you think you might find useful.

Contents

  VSP - Very Small Pinger
  SCRNMODE - Screen Mode Changer
  RMMINUSR - Recursive Delete
  DOFF - Print Date/Time With Offset
  STOPWATCH - Time Batch File Execution
  MEMLOG - Log Memory Usage
VSP - Very Small Pinger

Download, (Source included)

This program, weighing in at 8K, pings a specified host every 55 seconds, and displays the status in the System Tray. I wrote it because I work on a system where the remote end of the connection only comes up periodically, and then only stays up while there is activity on the line. I can leave vsp running in the tray and wait for the green light, knowing that the ping activity is enough to keep the link open if I'm away from my machine when the link comes up.

There are plenty of programs that offer this functionality and more, but I didn't want some 1-2M monster to perform this simple task.

SCRNMODE

Download, (Source included)

This is a quick and dirty program for changing screen mode, (resolution, color depth, etc.), and then optionally running a specified program. It is useful for running apps/games that only run in a specific screen mode. For example, I run this program from a shortcut to start WinTV in 640x480 mode, since WinTV's "full-screen" option will only work at this resolution, (due to limitations of my video driver).

Run the program directly, (with no parameters), for a list of screen modes supported by your display. Specify a display mode as a parameter to change the display mode. You can also specify the name of a program to run after changing the display.

C:\>scrnmode 11 "C:\Program Files\WinTV\wintv.exe"

This sets the display mode to 11, then runs "wintv.exe". If the program to run also takes parameters, include them as a third parameter to scrnmode. (Enclose multiple parameters in quotes if necessary.) To reset the display mode to the original setting, run the program with "reset" as a parameter instead of a display number.

C:\>scrnmode reset

WARNING!: Changing display modes dynamically can hang certain Windows configurations. Avoid using this program any time you have important unsaved data in open applications. Please do not blame, (or flame), me if things get messed up.

RMMINUSR

Download
Source

RMMINUSR deletes files recursively, (that is, it searches through sub-folders). For example:

C:\>rmminusr *.tmp

This will remove all files on C: that have a .tmp extension, (assuming its run in the "root" directory). This utility is useful for clearing out log files and temporary files that typically clutter up the root drive on a Windows machine. Note that this utility does not give any delete confirmation messages - Use with care! Unix users should recognise where I came up with the name.

DOFF

Download
Source

DOFF prints a formatted date and time, with an optional date offset, (e.g -1 prints yesterday's date, +1 prints tomorrow's date). To view all the options available, execute "doff -h". I typically use this utility for renaming log files so that they include a timestamp, (see the third example below). This code should compile under Unix/Linux, as well as DOS.

Sample commands:

C:\>doff
19991108131135


With no parameters the output is the current date/time in the following format: yyyymmddhhmiss

C:\>doff mm/dd/yyyy
11/08/1999


In the above example a date format specification is given.

@echo off
for /f "tokens=1-3 delims=/ " %%a in ('doff mm/dd/yyyy -1') do (
set mm=%%a
set dd=%%b
set yyyy=%%c)
rename httpd-access.log httpd-access-%yyyy%%mm%%dd%.log

The sample batch file above shows a neat way to rename a log file based on yesterday's date. The "for" command executes doff to print yesterday's date, (the "-1" parameter specifies yesterday), then extracts each component of the date into DOS batch file variables. The "rename" command renames "httpd-access.log" to "httpd-access-[yesterday's date].log"

STOPWATCH

Download
Source

STOPWATCH can be used to calculate the elapsed time, (in seconds), in a batch file. It does this by redirecting the current time out to a file when the "start" command is given, and then reading that time back in when a "stop" command is given. For example:

C:\>stopwatch start > timestamp.txt
... other batch commands here ...
C:\>stopwatch stop < timestamp.txt
10

Note that the output from the stop command can be piped or redirected to a program or file if required, and multiple "stop" commands can be executed to get intermediate timestamps. If you want to save the output of the "stopwatch stop" command to a variable, DOS/Windows doesn't make things easy for you. Here's an example that includes an ugly workaround to get the elapsed time into a variable called "elapsed_time":

@echo off
stopwatch start > timestamp.txt
... other batch commands here ...
stopwatch stop < timestamp.txt > elapsed.txt
for /F %%a in ('type elapsed.txt') do set /a elapsed_time=%%a
echo %elapsed_time%


MEMLOG

Download
Source

MEMLOG logs Windows memory usage. By default, it checks every 5 seconds though this can be changed by specifying the interval, (in milliseconds), on the command line:

C:\>memlog 1000
1999/11/08,13:16:43,41820160,131334144,2139750400,100159488,131334144,2143289344
1999/11/08,13:16:44,41803776,131334144,2139750400,100159488,131334144,2143289344
1999/11/08,13:16:45,41803776,131334144,2139750400,100159488,131334144,2143289344
1999/11/08,13:16:46,41803776,131334144,2139750400,100159488,131334144,2143289344
1999/11/08,13:16:47,41803776,131334144,2139750400,100159488,131334144,2143289344
1999/11/08,13:16:48,41803776,131334144,2139750400,100159488,131334144,2143289344
1999/11/08,13:16:49,41803776,131334144,2139750400,100159488,131334144,2143289344

The above command checks memory every second. Specify an interval of 0 to check memory one time only and then exit. The output is:
Date,Time,Free Physical,Free Page,Free Virtual,Total Physical,Total Page,Total Virtual

Memory figures are in bytes.

To save the output, redirect it to a file:

C:\>memlog 1000 > mem.csv

Note: Excel will recognize a ".csv" extension as a comma-separated file and will load it directly in spreadsheet format.