|
|
Environ() Function
[edit] Environ() FunctionsThe following is a list of common environment variables. Code is also provided that loops to enumerate custom environment variables.
[edit] Loop CodeYou 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
[edit] UsageTypically used to get a Users logged on name Environ("username") or information about the system. [edit] Before you use itOne 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. [edit] APIsBelow 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
[edit] SummaryThe 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
|
| This page was last modified 17:02, 11 February 2012. This page has been accessed 2,074 times. Disclaimers |