UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Environ() Function    
Environ() Function

Contents

Environ() Functions

The following is a list of common environment variables. Code is also provided that loops to enumerate custom environment variables.

A

ALLUSERSPROFILE | APPDATA | AVENGINE

C

CLIENTNAME | CommonProgramFiles | COMPUTERNAME | ComSpec

F

FP_NO_HOST_CHECK

H

HOMEDRIVE | HOMEPATH

I

INCLUDE | INOCULAN

L

LIB |LOGONSERVER

N

NUMBER_OF_PROCESSORS

O

OS

P

Path | PATHEXT | PROCESSOR_ARCHITECTURE | PROCESSOR_IDENTIFIER | PROCESSOR_LEVEL | PROCESSOR_REVISION | ProgramFiles

S

SESSIONNAME | SystemDrive | SystemRoot

- T

TEMP | TMP

U

USERDOMAIN | USERNAME | USERPROFILE

V

VS71COMNTOOLS

W

WecVersionForRosebud.FF0 |windir


Loop Code

You can write a loop to enumerate them. A typical number to use for the loop would be 50 because generally the list returned will always be less than that, but you could certainly increase it if needed.

This code will print out the name and value of the environment variables on a given machine.

CODE

Sub test()
   Dim i As Integer
   Dim stEnviron As String
   For i = 1 To 50
       ' get the environment variable
       stEnviron = Environ(i)
       ' see if there is a variable set
       If Len(stEnviron) > 0 Then
           Debug.Print i, Environ(i)
       Else
           Exit For
       End If
   Next
End Sub


Usage

Typically used to get a Users logged on name Environ("username") or information about the system.

Before you use it

One should note, before using the Environ() function, that these variables are quite easily editable by the average windows user, which, in some cases, may compromise their integrity. For example, a user can go to System Properties, under the Advanced tab, and click the Environment Variables to edit any of the listed variables (or add new ones, or remove existing ones).

For cases where the developer absolutely must have the actual system value, regardless of what changes may have been made to the environment variables by the user of the computer, it is recommended to use the APIs provided for this information.

APIs

Below is a list of some APIs found at the mvps.org/access website which will give you some of the same information as what people may commonly refer to the Environ() function for. Login Name Computer Name Temp/System Directories Special Folder Locations


Summary

The Environ() Function returns the string associated with an operating system environment variable. Note that it's not available on the Macintosh Custom environment variables could also be created and vary by system. See also Microsoft Office OnLine Access 2007

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 13,423 times.  This page was last modified 17:02, 11 February 2012 by Jack Leach. Contributions by Alan Greenwood and Anonymous user(s) of Access wiki - Access Help and How-to - Microsoft Office   Disclaimers