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

Parameters

  • name
    A String containing the name of the environment variable.

Return Value

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

Exceptions

The following conditions can cause an exception:

Remarks

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.

Example

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

Requirements

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

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

No

Windows Service

Yes

Web Site

No

Permissions

No permissions are required.

See Also

Reference

My.Application Object

GetEnvironmentVariable

GetEnvironmentVariable