EDN logo


Design Ideas: February 2, 1995

Program flags dangerous DOS commands

M N Jayaram,
BARC, Bombay, India

Windows users still perform many small housekeeping tasks, such as renaming, moving, or deleting files, by switching to DOS, because DOS is much faster than the time-consuming, icon-driven facilities of Windows.

However, you should not use certain DOS features, such as CHKDSK or tape backup, when Windows is running. Windows, because it is a multitasking operating system, maintains several open and swap files. Any changes to the FAT (file-allocation table) or directory structure may result in loss or corruption of data.

You can pre-empt the dangerous DOS commands by providing an appropriate .COM driver program to kick off the corresponding .EXE file. Listing 1 shows a debug script, safedos.scr. To create the file CHKDSK.COM, for example, execute the DOS command:

debug <safedos.scr

Because files with .COM extensions receive higher priority than files with .EXE extensions, DOS will execute the program CHKDSK.COM when you enter CHKDSK. To create other .COM files to kick off their corresponding .EXE files, change the lines

db 'c:\dos\chkdsk.exe',0
nchkdsk.com

in debug-script safedos.scr appropriately.

An environment variable called windir exists when Windows is running. This environment variable is unique because it is the only environment variable stored in lower case. All other environment variables are in upper-case characters. (DOS's SET command can create environment variables in upper case only.) The program scans the "environment" (DOS-ese for a reserved section of memory) for the environment-variable windir. If found, the program exits with the error message "Shutdown Windows!". Otherwise, the program loads and executes c:\dos\chkdsk.exe.

Because a .COM program assumes that it is the sole owner of the entire memory, you must free the memory not needed by the program so that it can safely and successfully execute a child process. Before freeing the additional memory, you must move the stack pointer to within the program area. The text attached to EDN BBS /DI_SIG #1650 contains the program and documentation. (DI#1650)


| EDN Access | feedback | subscribe to EDN! |
| design features | design ideas | columnist |


Copyright © 1995 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.