Search Tools Links Login

Using Environ


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.

Original Author: Zinna Pro

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:




  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  


  
  

ExpressionWhat came from my computer
ALLUSERSPROFILEH:Documents and SettingsAll Users
APPDATAH:Documents and SettingsinnaProApplication
  Data
CLIENTNAMEConsole
CommonProgramFilesH:Program FilesCommon Files
COMPUTERNAMELOCALHOST
ComSpecH:WINDOWSsystem32cmd.exe
HOMEDRIVEH:
HOMEPATHDocuments and SettingsinnaPro
LOGONSERVER\LOCALHOST
NUMBER_OF_PROCESSORS1
OSWindows_NT
PathH:WINDOWSsystem32;H:WINDOWS;H:WINDOWSSystem32Wbem
PATHEXT.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTUREx86
PROCESSOR_IDENTIFIERx86 Family 6 Model 6 Stepping 2, AuthenticAMD
PROCESSOR_LEVEL6
PROCESSOR_REVISION0602
ProgramFilesH:Program Files
SystemDriveH:
SystemRootH:WINDOWS
TEMPH:DOCUME~1innaProLOCALS~1Temp
TMPH:DOCUME~1innaProLOCALS~1Temp
USERDOMAINLOCALHOST
USERNAMEZinnaPro
USERPROFILEH:Documents and SettingsinnaPro
windirH: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


 



About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 98 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.