Detect if a batch file is executed within Windows

It is possible to detect within a batch file if it was executed in a Windows environment. This is done by checking for the environment variable WINDIR, which is exists in the Windows environment. This can be used ex. if having an application that cannot execute properly in the Windows environment:

@EHCO OFF
IF NOT “%WINDIR%”==”” GOTO EXIT
DOSPROG.EXE
:EXIT

More Info MS KB85469

Note one can also check whether one is executing in Windows NT or Windows 9x. This is done by checking for the enviroment variable SYSTEMROOT, which is created by the Windows NT enviroment:

@EHCO OFF
IF NOT “%SYSTEMROOT%”==”” GOTO WINNT
IF NOT “%WINDIR%”==”” GOTO WIN9X
GOTO DOS

More Info MS KB190899