Windows Environment Variables in VB

Discussion in 'Visual Basic [VB]' started by shabbir, Nov 24, 2004.

  1. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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:
      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
      
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    Really helpful. I just needed the JAVA_HOME to run and compile the code.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice