Export (0) Print
Expand All

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

name

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 Environment.GetEnvironmentVariable(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()
    Try
        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

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

No

Windows Service

Yes

Web Site

No

No permissions are required.

Community Additions

ADD
Show:
© 2014 Microsoft