GetEnvironmentVariable Method (My.Application Object)
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

My.Application.GetEnvironmentVariable Method 

Returns the value of the specified environment variable.

' Usage
Dim value As String = My.Application.GetEnvironmentVariable(name)
' Declaration
Public Function GetEnvironmentVariable( _
   ByVal name As String _
) As String



A String containing the name of the environment variable.

A String containing the value of the environment variable with the name name.

The following conditions can cause an exception:

The My.Application.GetEnvironmentVariable method returns the environment variable with the name name. This method is similar to System.Environment.GetEnvironmentVariable(System.String), except that this method raises an exception if the environment variable specified by name does not exist.

This example uses the My.Application.GetEnvironmentVariable method to get and display the value of the PATH environment variable, if available. Otherwise, it displays a message indicating that the PATH environment variable does not exist.

Private Sub TestGetEnvironmentVariable()
        MsgBox("PATH = " & My.Application.GetEnvironmentVariable("PATH"))
    Catch ex As System.ArgumentException
        MsgBox("Environment variable 'PATH' does not exist.")
    End Try
End Sub

Namespace: Microsoft.VisualBasic.ApplicationServices

Class: WindowsFormsApplicationBase, ApplicationBase

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type Available

Windows Application


Class Library


Console Application


Windows Control Library


Web Control Library


Windows Service


Web Site


No permissions are required.

© 2015 Microsoft