Using ENVIRON$ to Detect Whether Running Under Windows (82002)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1
  • Microsoft Cinemania for Windows 1993 edition
  • Microsoft Windows 3.0
  • Microsoft Windows 3.1
  • Microsoft GW-Basic Interpreter 3.20
  • Microsoft GW-Basic Interpreter 3.20 and later
  • Microsoft GW-Basic Interpreter 3.22
  • Microsoft GW-Basic Interpreter 3.23

This article was previously published under Q82002

SUMMARY

A Microsoft Basic program can detect whether it is running under Microsoft Windows by checking for the existence of the environment variable "windir" with the function ENVIRON$.

This information applies to Microsoft QuickBasic versions 4.0, 4.0b, and 4.5 for MS-DOS; Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS; Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS; Microsoft GW-Basic Interpreter versions 3.2, 3.22, and 3.23 for MS-DOS; and Microsoft Windows versions 3.0 and 3.1.

MORE INFORMATION

When Windows runs a program, it supplies the environment variable named "windir" that specifies the full path of the directory where Windows is installed. Note that this environment variable name is spelled with lowercase letters.

If a Basic program is running under Microsoft Windows, the expression ENVIRON$("windir") returns a non-null string, otherwise it returns a null string.

Example Code

IF ENVIRON$("windir") <> "" THEN
    PRINT "running under Windows"
ELSE
    PRINT "not running under Windows"
END IF
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB82002