Knowing the environment variables in your program can sometimes be a very important aspect of your application. It’s very easy to get a list of and to use any one of the environment variables however you need it.

Here’s how you can get a list of them in code (Add a textbox to your form and name it ‘textbox1′):

VB.Net:
Private Sub GetEnvironmentVariables()
   For Each dictItem As DictionaryEntry In Environment.GetEnvironmentVariables()
            TextBox1.Text += dictItem.Key.ToString() & ":  " & _
                dictItem.Value.ToString() & vbCrLf
        Next
End Sub
C#:
private void GetEnvironmentVariables() {
    foreach (DictionaryEntry dictItem in Environment.GetEnvironmentVariables()) 
       {
            TextBox1.Text = (TextBox1.Text 
                        + (dictItem.Key.ToString() + (":  " 
                        + (dictItem.Value.ToString() + "\r\n"))));
        }
    }

To use any one of them in code, simply do something like this:

Label1.text=System.Environment.ComputerName