devxlogo

Retrieve Windows and System directories

Retrieve Windows and System directories

In VB.NET you don’t need to call the GetWindowsDirectory and GetSystemDirectory API functions to retrieve the path the Windows and System directories. Retrieving the System directory is as simple as calling the Environment.SystemDirectory property:

Dim sysDir As String = Environment.SystemDirectory()

The Environment class doesn’t expose any property that returns the Windows directory; however, it is simple to extract the first portion of the system directory’s path, by using the GetDirectoryName method of the System.IO.Path class:

Dim winDir As String = System.IO.Path.GetDirectoryName _    (Environment.SystemDirectory)

Alternatively, you can retrieve the Windows directory by reading the WINDIR environment variable:

winDir = Environment.GetEnvironmentVariable("WINDIR")

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist