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")

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: