How to Call Environment Variables From Visual Basic

Environment variables are saved settings for the operating system. For instance, a common environment variable is the location of the operating system files. The environment variable allows other applications to know what hard drive and directory contains the system files. These settings are used by applications through programming languages such as Visual Basic.

Instructions

    • 1

      Use the environment class. .NET Visual Basic has a class specific for calling environment variables.

    • 2

      Print the machine name. For network programming, use the "MachineName" property. The code below prints the name of the computer, which is used for locating a machine on the network.

      Console.WriteLine("This is the Machine's Network Name: " + Environment.MachineName)

    • 3

      Find the operating system, system files and username. Knowing the operating system of the computer can personalize application settings for different systems. System files are used for applications that need to use internal Windows functions.

      Console.WriteLine("Operating System: " & Environment.OSVersion.ToString())Console.WriteLine("System Files Directory: " + Environment.SystemDirectory)Console.WriteLine("User: " + Environment.UserName)

    • 4

      Get the version of the operating system. For instance, a computer may be a server or desktop. Depending on the version, the computer may use an application differently and have different settings.

      Console.WriteLine("Operating System Version: " + Environment.Version.ToString())

    • 5

      Find drive letters. You may want to know what drives are available for an application. This loop iterates through a list of drive letters and prints them to the console.

      Dim mydriveletters As String()
      Dim i As Int32
      mydriveletters = Environment.GetLogicalDrives()
      Console.WriteLine("Drive Letter:")
      For counter = 0 To mydriveletters.Length - 1
      Console.WriteLine(mydriveletters(i).ToString())
      Next

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured