home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
utility
/
pbaseiv.zip
/
P4UTL001.TIP
< prev
next >
Wrap
Text File
|
1991-12-16
|
3KB
|
72 lines
I frequently want my batch files to know whether a DOS
program is running from within a Windows DOS virtual machine
or from the DOS prompt alone. According to Microsoft, it's
dangerous to run certain programs, such as CHKDSK, while
you're in Windows. I also need to write batch files that
display a message telling the user how to switch back to
Windows with a hot key.
I discovered that when Windows is running, it creates an
environment variable with the name `windir' that points to
the Windows directory. Normally, one can test for variables
with the `==' operator, but `==' assumes that variable names
are all uppercase, and `windir' is lowercase. (Microsoft
probably did this so the SET command couldn't create or
change the variable.) Any reference to `windir' in a batch
file actually looks for a variable named `WINDIR,' which
isn't the same thing.
To circumvent this problem, I wrote a small assembly
language program that searches for `windir.' If it's found,
the program returns an ERRORLEVEL of 1; otherwise it returns
an ERRORLEVEL of 0. I called the program InWinEQ1, which is
a mnemonic for "In Windows Equals 1." CHKDSK.BAT [below]
shows how you can use InWinEQ1 to prevent users from running
CHKDSK from within Windows. First, put CHKDSK.BAT and
INWINEQ1.COM in a directory listed in your PATH command and
rename your DOS directory's CHKDSK.COM to CHKDSK!.COM
(depending on your DOS version, CHKDSK may be an EXE
program). When a user types CHKDSK, the batch file will
check to see if Windows is running. If it is, InWinEQ1 will
return an ERRRORLEVEL of 1, and the batch file will go
directly to the :INWINDOWS line, skipping the CHKDSK!
command. You can easily modify this batch file for other
purposes.
Christopher J. Stein
Durham, North Carolina
Editor's note: The Windows documentation says that running
CHKDSK, SUBST, JOIN, FASTOPEN, or ASSIGN in a Windows DOS
virtual machine can cause major problems, but Microsoft does
nothing to prevent this from happening. Mr. Stein's
technique makes sure you don't lock up your machine--or
worse, corrupt your disk.
InWinEQ1 is included, in executable form, in the P4UTIL
directory on your PowerBase *.* Volume IV diskette. To use
it, copy it to any directory on your PATH. You can copy the
sample listing in this tip to a file by pressing the Alt-F
key.
CHKDSK.BAT -- A demonstration of InWinEQ1
---- BEGIN LISTING ----
@ECHO OFF
InWinEQ1
IF ERRORLEVEL 1 GOTO INWINDOWS
CHKDSK! %1 %2 %3
GOTO DONE
:INWINDOWS
ECHO You cannot run CHKDSK from inside Windows!
:DONE
ECHO ON
---- END LISTING ----
Title: Am I Weally in Windows?
Category: MSC
Issue date: Dec 1991
Editor: Brett Glass
Supplementary files: P4UTIL\INWINEQ1.COM