Redigera

Dela via


ApplicationBase.GetEnvironmentVariable(String) Method

Definition

Returns the value of the specified environment variable.

public:
 System::String ^ GetEnvironmentVariable(System::String ^ name);
public string GetEnvironmentVariable (string name);
member this.GetEnvironmentVariable : string -> string
Public Function GetEnvironmentVariable (name As String) As String

Parameters

name
String

A String containing the name of the environment variable.

Returns

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

Exceptions

name is Nothing.

The environment variable specified by name does not exist.

The calling code does not have EnvironmentPermission with Read access.

Examples

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

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.

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

Applies to

See also