Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic [VB] (http://www.go4expert.com/articles/visual-basic-tutorials/)
-   -   Windows Environment Variables in VB (http://www.go4expert.com/articles/windows-environment-variables-vb-t208/)

shabbir 24Nov2004 17:00

Windows Environment Variables in VB
 
Visual Basic 6 provides a function called Environ through which you can get all the environment variables available. It takes string parameter which is name of the Environment variable and returns its value.

The Valid Environment strings are

ALLUSERSPROFILE
APPDATA
CI_HOLOS_CLI
CLIENTNAME
CommonProgramFiles
COMPUTERNAME
ComSpec
FP_NO_HOST_CHECK
HOMEDRIVE
HOMEPATH
include
JAVA_HOME
lib
LOGONSERVER
MSDevDir
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramFiles
SESSIONNAME
SystemDrive
SystemRoot
TEMP
TMP
USERDNSDOMAIN
USERDOMAIN
USERNAME
USERPROFILE
windir

The following code will help you get all the Environment variables on your system
Code: VB

Dim i as Integer
  Text1.Text = ""
  i = 1
  While Environ$(i) <> ""
    Text1.Text = Text1.Text + Mid(Environ$(i), 1, InStr(1, Environ(i), "=") - 1) + vbNewLine
    i = i + 1
  Wend


coderzone 2Sep2005 04:28

Re: Windows Environment Variables in VB
 
Really helpful. I just needed the JAVA_HOME to run and compile the code.


All times are GMT +5.5. The time now is 11:43.