Export (0) Print
Expand All

ApplicationBase.GetEnvironmentVariable Method

Returns the value of the specified environment variable.

Namespace:  Microsoft.VisualBasic.ApplicationServices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public string GetEnvironmentVariable(
	string name
)

Parameters

name
Type: System.String

A String containing the name of the environment variable.

Return Value

Type: System.String
A String containing the value of the environment variable with the name name.

ExceptionCondition
ArgumentNullException

name is Nothing.

ArgumentException

The environment variable specified by name does not exist.

SecurityException

The calling code does not have EnvironmentPermission with Read access.

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

Availability by Project Type

Project type

Available

Windows Forms Application

Yes

Class Library

Yes

Console Application

Yes

Windows Forms Control Library

Yes

Web Control Library

No

Windows Service

Yes

Web Site

No

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()
    Try
        MsgBox("PATH = " & My.Application.GetEnvironmentVariable("PATH"))
    Catch ex As System.ArgumentException
        MsgBox("Environment variable 'PATH' does not exist.")
    End Try 
End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft