How To Get Environment Variables In VB.NET and C#


Environment
Environment Variables are set of values that are used for running special processes or special system files.. for example when you install java or python you must make a new environment variable in order to compile and run java or python programs that's all I know about it. Without wasting anytime let's get into it...

This is a simple code that will show you the environment variables..

For VB.NET

        Dim EV As String = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process Or EnvironmentVariableTarget.Machine)

        MsgBox(EV)

For C#

'you must add these namespaces 

using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;

'add this code in an event 
string EV = Environment.GetEnvironmentVariable("PATH", 
                EnvironmentVariableTarget.Process | 
                EnvironmentVariableTarget.Machine);
            MessageBox.Show(EV);

The "PATH" defines the environment variable name so if you want to get another ones just change PATH with the variable name.