README.md

December 4, 2022 · View on GitHub

Using Environ

Description

Many people ask how to get certain system information and environ is the solution.

Environ is a command that allows you to get system environmental information.

It can also get any of the Environment Variables from the [System Properties, Advanced, Environment Variables] settings in windows.

More Info

Submitted On
ByZinna Pro
LevelIntermediate
User Rating4.7 (14 globes from 3 users)
CompatibilityVB 5.0, VB 6.0
CategoryWindows System Services
WorldVisual Basic
Archive File

Source Code

Using Environ

  • Environ is a command that allows you to get system environmental information.
  • It can also get any of the Environment Variables from the [System Properties, Advanced, Environment Variables]  settings in windows.

Syntax: Environ(expression)

Where expression is includes the environmental variable you wish to retrieve

Example:

Call MsgBox("Your Temp Directory is: " & Environ("Temp"), vbInformation, "Temp Directory Finder")

List of Common Expressions and sample output:

Expression What came from my computer
ALLUSERSPROFILE H:\Documents and Settings\All Users
APPDATA H:\Documents and Settings\ZinnaPro\Application Data
CLIENTNAME Console
CommonProgramFiles H:\Program Files\Common Files
COMPUTERNAME LOCALHOST
ComSpec H:\WINDOWS\system32\cmd.exe
HOMEDRIVE H:
HOMEPATH \Documents and Settings\ZinnaPro
LOGONSERVER \\LOCALHOST
NUMBER_OF_PROCESSORS 1
OS Windows_NT
Path H:\WINDOWS\system32;H:\WINDOWS;H:\WINDOWS\System32\Wbem
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE x86
PROCESSOR_IDENTIFIER x86 Family 6 Model 6 Stepping 2, AuthenticAMD
PROCESSOR_LEVEL 6
PROCESSOR_REVISION 0602
ProgramFiles H:\Program Files
SystemDrive H:
SystemRoot H:\WINDOWS
TEMP H:\DOCUME~1\ZinnaPro\LOCALS~1\Temp
TMP H:\DOCUME~1\ZinnaPro\LOCALS~1\Temp
USERDOMAIN LOCALHOST
USERNAME ZinnaPro
USERPROFILE H:\Documents and Settings\ZinnaPro
windir H:\WINDOWS

Full List of variables my computer can get:

  • ALLUSERSPROFILE
  • APPDATA
  • CLIENTNAME
  • CommonProgramFiles
  • COMPUTERNAME
  • ComSpec
  • DRIVERNETWORKS
  • DRIVERWORKS
  • HOMEDRIVE
  • HOMEPATH
  • include
  • lib
  • LOGONSERVER
  • MSDevDir
  • NUMBER_OF_PROCESSORS
  • OS
  • Path
  • PATHEXT
  • PROCESSOR_ARCHITECTURE
  • PROCESSOR_IDENTIFIER
  • PROCESSOR_LEVEL
  • PROCESSOR_REVISION
  • ProgramFiles
  • SESSIONNAME
  • SystemDrive
  • SystemRoot
  • TEMP
  • TMP
  • USERDOMAIN
  • USERNAME
  • USERPROFILE
  • VTOOLSD
  • windir

Code used to get all variables:

Dim environinfo as string 'Declare environinfo variable as string
On Error goto done 'If an error occurs then goto end (error expected due to large for loop)
environinfo = "" 'Set our variable to nothing
For i = 1 To 200 'Do a large for loop and try 200 environmental indexes augmenting i by 1
   environinfo = environinfo & Environ(i) & vbCrLf 'Augment variable and add put on separate lines
Next i 'Loop until i is 200

done: 'Where to go on error, means we are done in this case
clipboard.settext environinfo 'Copy our variable information to clipboard
Call MsgBox("Your Environment Variables have been copied to clipboard", vbInformation, "Environs Found") 'alert the user that the variables are in clipboard