VERIFIED SOLUTION i

Using MapInfo MapBasic to find a Windows operating system Environment variable

products affected: MapInfo Pro™, MapBasic™
An example of how to use the MapBasic Env$() function to find a Windows operating system environment varialbe.


Env$() function


Purpose
Get an Environment variable used by Windows operating system.

Syntax
Env$(environmentvar)
Where environmentvar is a string representing a system environment variable such as PathLOCALAPPDATA, etc.

To see a list of environment variables available for use, open a DOS command prompt and type 'Set' and hit <Enter>.

Return Value
String
Description

Get an operating system environment variable such as System TEMP folder, PATH, USERNAME, APPDATA, etc.

Examples
Print Env$("TEMP")
Output should be like 'C:\Temp' or 'C:\Windows\Temp'.
Print Env$(SystemRoot)
Output would typically be 'C:\Windows'

Error Conditions
  • If an empty string or non-string parameter is passed to function an error will be thrown.
  • If a non-existent variable name (e.g.: "FooBar") is passed to function an empty string will be returned.
  • This is basically querying for a name that is not set, so an empty string will be returned.
UPDATED:  February 25, 2019